Skip to content

perf(agent-org): reuse bounded time formatters - #1224

Open
ShiboSheng wants to merge 1 commit into
fix/issue-803-orphan-coordinator-paginationfrom
fix/issue-765-group-activity-formatter-memory
Open

perf(agent-org): reuse bounded time formatters#1224
ShiboSheng wants to merge 1 commit into
fix/issue-803-orphan-coordinator-paginationfrom
fix/issue-765-group-activity-formatter-memory

Conversation

@ShiboSheng

Copy link
Copy Markdown
Collaborator

Problem

Fixes #765

Repeatedly switching between the Agent Org Group projection and individual Member pages rebuilt browser-local Intl.DateTimeFormat / ICU formatters during rendering. The Group activity rows, Member turn-page range, Member timing labels, and discussion events bypassed the existing bounded formatter cache, creating avoidable WebKit allocation churn across remounts.

The remaining ps RSS increase is not retained dirty memory: macOS footprint classifies more than the RSS delta as reclaimable JavaScriptCore pages while physical footprint and dirty WebKit malloc both fall below baseline. This PR fixes the real formatter churn and records both metrics rather than claiming that raw RSS immediately returns pages to the OS.

Solution

Add short local-time helpers backed by the existing 64-entry Intl.DateTimeFormat LRU and route every affected Group/Member hot path through them. The helpers preserve the prior locale inputs and formatting options, including the Member page's 24-hour output.

The resulting invariant is: Agent Org render paths must reuse the shared bounded date formatter instead of constructing locale formatters per render. Regression tests cover the Group projection owner and prove that repeated Member page/timing formatting does not call Date#toLocaleTimeString or construct additional Intl.DateTimeFormat instances.

Potential risks

  • Timestamp text is intended to remain unchanged; output-parity tests cover the existing locale/options combinations, but other operating-system locales were not manually enumerated.
  • A formatter resolved from the operating system's default locale remains cached until eviction or process restart. This matches the repository's existing bounded formatter behavior but means an in-process OS locale change is not reflected immediately.
  • Raw WebContent RSS still rises because JavaScriptCore keeps reclaimable heap pages. The physical footprint, dirty WebKit malloc, and hidden lifecycle gates pass, but this change does not promise immediate OS reclamation of RSS pages.
  • Verification used the macOS BuildFast package. Windows/Linux runtime behavior and release-only signing, notarization, updater, and installer paths were not exercised because this is a frontend-only allocation fix.
  • There are no persistence, schema, IPC, wire-format, dependency, or data changes. Rollback is a normal revert of this commit; no data recovery is required.

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/util/data/formatters/dateLocalDisplay.test.ts src/engines/ChatPanel/ChatHistory/utils/__tests__/turnPageFormatting.test.ts src/engines/ChatPanel/ChatHistory/utils/__tests__/turnTimingFormatting.test.ts src/engines/ChatPanel/ChatHistory/utils/__tests__/turnFormattingIntlCache.test.ts src/engines/ChatPanel/ChatHistory/GroupChatView/__tests__/AgentOrgGroupProjectionView.test.ts — 5 files, 29 tests passed.
  • pnpm test -- --reporter=dot — 1,336 files and 10,516 tests passed.
  • pnpm run typecheck — passed.
  • pnpm run lint — oxlint and ESLint passed with zero errors/warnings.
  • pnpm run check:circular — no circular dependencies across 6,426 modules.
  • pnpm run check:test-placement — passed across 445 directories.
  • ORGII_AGENT_ORG_REDESIGN=1 pnpm run tauri:build:fast — passed; webpack runtime 49121; packaged src-tauri/target/dev-build/bundle/macos/ORG2.app in 494.9 seconds.
  • Packaged binary SHA-256: 862e7dc7656bb15081e1328b01620662717c581f7c0570da0a75d614d6bbe2d6.
  • Computer Use operated the packaged app against the real Flappy Bird Agent Org run: 2 preheat cycles, 20 Group → Planner → Group cycles, 5 minutes foreground idle, and 5 minutes hidden. The final UI remained on Group view with all 18 activity timestamps visible.
  • Visual screenshots are not useful for this change because the timestamp output is intentionally unchanged; the packaged-app lifecycle and memory measurements are the acceptance evidence.

Performance evidence

Stage WebContent RSS Physical footprint Dirty WebKit malloc Reclaimable Dirty graphics
After 20 cycles vs. post-preheat baseline +161.1 MiB -80.8 MiB -86.8 MiB +244.7 MiB 0 MiB
After 5 minutes foreground idle vs. baseline +196.1 MiB -84.7 MiB -86.9 MiB +347.8 MiB -3.7 MiB
Hidden minute 5 vs. hidden minute 1 +1.7 MiB -0.9 MiB -1.6 MiB +6.5 MiB +0.8 MiB

No polling, timer, subscription, worker, persistence, or cache-lifecycle mechanism was added. The hidden process showed no staircase growth after its transition.

Repeated team and member transitions rebuilt Intl formatters on each render, creating avoidable WebKit allocation churn. Route hot-path time labels through the shared 64-entry cache while preserving locale output.

Verification:
- pnpm test -- --reporter=dot (1323 files, 10381 tests passed)
- pnpm run lint
- pnpm run typecheck
- pnpm run check:circular (6403 modules)
- pnpm run check:test-placement (443 directories)
- ORGII_AGENT_ORG_REDESIGN=1 pnpm run tauri:build:fast
- Packaged ORG2: 20 Group/Planner cycles and 5-minute hidden idle
@ShiboSheng
ShiboSheng marked this pull request as ready for review September 2, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant