Skip to content

perf(logging): avoid intermediate timestamp objects - #134979

Merged
steipete merged 1 commit into
mainfrom
codex/perf-log-timestamp-parts-20260901
Sep 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-log-timestamp-parts-20260901

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Every formatted log timestamp builds an array of key/value pairs and then a second projected object before constructing the string. Console logging, structured file logging, overflow markers, and local-time CLI displays all pay this repeated work.

Why This Change Was Made

Keep the canonical formatTimestamp owner and collect native Intl parts directly into one private dictionary. Its sole consumer formats the offset and final string. Native Intl supplies a closed set of part names; repeated literal fields retain last-write-wins behavior. This removes the intermediate pair array and private projection without changing formatter options, timezone selection, caches, errors, redaction, or transport lifecycle.

Production: +10/-14, net -4 lines. Tests: unchanged. This is an internal, behavior-preserving optimization with no config, schema, protocol, SDK, or documentation contract changes.

User Impact

Less steady-state timestamp-formatting work on logging paths. Timestamp bytes remain unchanged. This does not claim a measurable reduction in model-turn latency, Gateway startup, total logging throughput, or memory usage.

Evidence

The complete source owner was measured with native Node 26.8.1 Intl, not an extracted private helper or a substitute formatter. Four fixed-order runs used before/candidate/candidate/before, retaining 756 measured blocks, 672 warmup blocks, and 84 first calls across 21 workloads. All 21 medians improved in both orders, including all 15 predeclared ordinary decision rows.

Complete formatter workload Forward before → candidate Reverse before → candidate
Default medium 3.212083 → 2.632000 µs (-18.06%) 3.325166 → 2.599791 µs (-21.81%)
Default long 3.197250 → 2.680916 µs (-16.15%) 3.231042 → 2.645125 µs (-18.13%)
Explicit UTC short 3.104208 → 2.539833 µs (-18.18%) 3.159042 → 2.533000 µs (-19.82%)

There were no slower median pairs, but 15 slower first-call pairs are retained. Forward UTC-short's first call rose from 8.231666 to 8.355208 ms. Only the first row is a cold formatter/cache call; later first calls reuse warmed caches. Forward driver system CPU rose by 358 µs and whole-process system CPU by 487 µs; this is not elapsed-time regression. These are four fixed-order processes, not a randomized statistical population. All first-call, CPU, wall-time, and RSS observations remain in the local campaign evidence, without a startup or memory claim.

The paired correctness run checked 63 exact pairs (60 values and three errors), 21 ordered workload oracles, all styles, timezone precedence, invalid/empty/absent zones, fractional offsets, DST edges, leap midnight, milliseconds, historical/extreme Dates, and error precedence. Direct V8 source inspection confirmed the native part-name/data-record contract. Independent review recomputed every measured median and checked raw journals, hashes, process/group closure, and runtime removal.

Source capture was 61763b06923071f1517c32b05243bddfa808a3d4; timing execution was e92637ab84fc0ca1786276cca141dc9e6cbbf510 with three unrelated SDK integration paths dirty. The formatter before/candidate bytes match current integration exactly; these are not relabeled current-head timing runs. Candidate SHA256: ed9a11d6cf2e704dc18706162ccece4bc280bedc464f7041d409e65879b95985. Raw numerical reduction: 61c4af6b8dcfee10d31bc8caedc38787b905b7beb505218199f29b95d8e683ce. Fresh independent report: 65f15b015d2cb0175ea9311d2d0e36368daa10b124331d9534509e1eb79e7fb0.

Canonical validation passed 78 tests before and 78 after across timestamp, console, file transport, capture, and subsystem suites:

node scripts/run-vitest.mjs src/logging/timestamps.test.ts src/logging/console-timestamp.test.ts src/logging/logger-timestamp.test.ts src/logging/logger-file-transport.test.ts src/logging/console-capture.test.ts src/logging/subsystem.test.ts --maxWorkers 1 --no-cache
pnpm check:changed -- src/logging/timestamps.ts

The complete changed gate passed (types, lint, formatting, boundaries, and Knip; 265.92 s). Managed Codex review finished scoped-clean at its configured P0 scope. Two unsuccessful review attempts are retained: the first failed the source-integrity preflight, the second encountered an unavailable model. The final supported public-model review passed without changing the candidate or weakening isolation.

Fresh integration at commit 71c263b13f3e040f3ac415758e2f81a564087d71 also passed:

  • Full pnpm build: 179.90 s. Existing dependency bundler warnings did not fail the build.
  • Isolated, freshly built Gateway with the real OpenAI provider: readiness 3548.85 ms; READY, batched tool discovery, exact file read, and sequential Markdown/text web fetches all completed. Both web requests returned HTTP 200 through the actual tool flow; 12 session-list responses and five system-event/status results passed.
  • Real logging readback: 209 structured file records and 203 captured console timestamp lines all have valid long timestamps with explicit local offsets. Their clocks are independent; no exact console/file clock equality is claimed.
  • Gateway main-thread CPU profile retained separately from its worker profile. All 12,350 built-runtime entries matched before/after and at root readback. The owned PID/group and loopback listener were gone, and temporary credential-bearing configs and FIFO were removed.

Real-provider turn timings were 1.48/3.57/5.42/7.84 s and are integration observations only. The existing conservative replayInvalid classification for generic tool_call remained true on read/web turns; no retry, fallback, or compaction recovery was exercised. Live readback SHA256: 00ddc78f408aa62fcea4ecc607c7cbaaa8415f10913ec25c132198d2764825fd.

Final landing checks: CI run 33483592680 succeeded on exact head 71c263b13f3e040f3ac415758e2f81a564087d71 on its first attempt. All 268 check entries completed without failure, cancellation, or timeout. The completed ClawSweeper review found no actionable correctness/security issue and requested ordinary maintainer review; that review is complete. A fresh managed review of the exact commit passed at P0 scope, and an independent live audit confirmed the actual console-prefix count, all transcript/tool evidence, profiles, and cleanup. Its report SHA256 is 566266888316f76a2fc115c41e9f0c7d2c961ab367501d7c1e7dbc089044d50c.

The native review-artifact validator initially rejected a missing space in its required header. The original artifact and failed attempt were retained, the exact stale operation lock was recovered after verifying no associated tools remained, and the corrected artifact passed validation. No source or test changes were made for that administrative retry.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 1, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 3:53 AM ET / 07:53 UTC.

ClawSweeper review

What this changes

The PR collects Intl.DateTimeFormat.formatToParts results directly into one private lookup object before producing console and file-log timestamps.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this maintainer-owned performance PR open for normal review. The introduced loop preserves the formatter’s key-to-value overwrite behavior while removing the pair-array and second projection; no concrete correctness or security defect was found.

Priority: P3
Reviewed head: 71c263b13f3e040f3ac415758e2f81a564087d71

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, focused internal optimization with a clear owner boundary and no identified regression.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-associated PR is exempt from the external-contributor proof gate; its body additionally describes a fresh Gateway logging readback, but no proof sufficiency claim is needed for this classification.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-associated PR is exempt from the external-contributor proof gate; its body additionally describes a fresh Gateway logging readback, but no proof sufficiency claim is needed for this classification.
Evidence reviewed 6 items Introduced formatter change: The raw-parent diff proves this PR alone introduces the direct part dictionary loop, moves offset formatting to the sole consumer, and rewrites all three render branches to use it.
Current-main comparison: Current main still has the prior Object.fromEntries(...map(...)) and shaped projection, so it has not already superseded this change.
Caller boundary: Console formatting is a direct consumer: pretty output removes the short timestamp’s offset, while compact and JSON styles retain the long timestamp.
Findings None None.
Security None None.

How this fits together

The shared logging timestamp formatter converts a Date and optional timezone into short, medium, or long local-offset strings. Console output, JSON diagnostics, and file transports consume those strings for operator-visible logs.

flowchart LR
  A[Date and timezone] --> B[Formatter cache]
  B --> C[Intl timestamp parts]
  C --> D[Offset and style rendering]
  D --> E[Console and file logs]
Loading

Before merge

  • Complete next step (P2) - No repair work is needed: the review found no actionable defect in this focused maintainer-owned PR.
Agent review details

Security

None.

PR surface

Source -4. Total -4 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 10 14 -4
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 10 14 -4

Review metrics

Metric Value Why it matters
Production versus test delta production -4 net, tests 0 The optimization removes the intermediate pair array and shaped projection without adding test-only or public-contract surface.

Technical review

Best possible solution:

Retain one private part lookup in the canonical formatter and preserve its exact timestamp output for every existing consumer.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR is a behavior-preserving performance optimization rather than a reported failure. The existing formatter tests provide the relevant output contract.

Is this the best way to solve the issue?

Yes. Keeping the collection and rendering in the one private formatter preserves the current overwrite semantics; emitting strings directly from ordered parts would couple the code to presentation ordering and add complexity.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e8c3fbc05b6b.

Labels

Label changes:

  • add P3: This is a small behavior-preserving logging optimization with limited user-impact scope.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-associated PR is exempt from the external-contributor proof gate; its body additionally describes a fresh Gateway logging readback, but no proof sufficiency claim is needed for this classification.

Label justifications:

  • P3: This is a small behavior-preserving logging optimization with limited user-impact scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-associated PR is exempt from the external-contributor proof gate; its body additionally describes a fresh Gateway logging readback, but no proof sufficiency claim is needed for this classification.

Evidence

What I checked:

  • Introduced formatter change: The raw-parent diff proves this PR alone introduces the direct part dictionary loop, moves offset formatting to the sole consumer, and rewrites all three render branches to use it. (src/logging/timestamps.ts:61, 71c263b13f3e)
  • Current-main comparison: Current main still has the prior Object.fromEntries(...map(...)) and shaped projection, so it has not already superseded this change. (src/logging/timestamps.ts:61, e8c3fbc05b6b)
  • Caller boundary: Console formatting is a direct consumer: pretty output removes the short timestamp’s offset, while compact and JSON styles retain the long timestamp. (src/logging/console.ts:152, 71c263b13f3e)
  • Existing behavior coverage: Existing tests assert exact UTC output, named-zone offsets, all three styles, milliseconds, and invalid-zone fallback at the exported formatter boundary. (src/logging/timestamps.test.ts:5, 71c263b13f3e)
  • Intl contract: The installed TypeScript Intl contract defines formatToParts as an array of { type, value } records and includes the part names used by the renderer; assigning each record to the same key preserves the old Object.fromEntries last-write-wins behavior.
  • Feature history: Formatter caching in this file dates to Peter Steinberger’s earlier perf: cache log timestamp formatters commit; a later logging refactor was committed by Vincent Koc. (src/logging/timestamps.ts:42, 51dee73a5d3e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 2a920ab into main Sep 1, 2026
274 checks passed
@steipete
steipete deleted the codex/perf-log-timestamp-parts-20260901 branch September 1, 2026 08:04
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant