Companion to vscode-performance-discipline.md. This is a read-only analysis: three passes over
this repository (boot path, session data plane, concurrency/lifecycle), mapped against the VS Code
practices. No code was changed. Every claim carries a file reference; all file:line pointers were
verified during the analysis pass. Machine-specific counts (e.g. "261 links") were measured on this
machine at analysis time.
| VS Code discipline | Status in this repo | Headline evidence |
|---|---|---|
| 1. Measure first, budgets always | Missing on the boot path | Loader envData.startTime exists with zero consumers; no performance.now in any boot module |
| 2. Lazy loading / activation events | Partial | Composition is all-or-nothing (~97 eager import+activations in headless); some lazy islands exist |
| 3. Progressive boot / idle scheduling | Missing | No requestIdleCallback anywhere; boot fs phases are synchronous-serial |
| 4. Viewport-proportional work | Partial | Streaming and projection folds are incremental; resume and one per-event snapshot are full-log |
| 5. Disposables + mechanized leak detection | Lifecycle strong, detection missing | Effect-based disposal is uniform; no FinalizationRegistry, no test-global leak tracker |
| 6. Fix memory in data structures | Inverted at the read path | Durable log is append-only and batched (excellent); live session retains the full log in RAM and resume reloads all of it |
| 7. Keep the main thread cheap | Largely applied | worker_threads, child_process, node-pty, remote sandbox, async streaming with incremental SSE parse |
| 8. Bounded caches | Mostly applied | WeakMaps, rings, LRU prepared-session cache; two gaps found (jobs-local, SDK client queues) |
The boot sequence (pnpm dsh --profile headless "task"): apps/cli/src/bin.ts →
loadLayeredEnv (packages/boot/app-boot/src/index.ts:177) → prepareProfile/composeProfile
(apps/cli/src/profile-boot.ts:100,155) → boot() (app-boot/src/index.ts:759) → Loader/Include
mount → entry tree import+activation → typert pass → settlement → first LLM request.
| Cost | Location | Scale |
|---|---|---|
| Synchronous dependency-closure BFS + symlink healing, every boot | packages/boot/app-boot/src/profile.ts:223 (healProfilesModuleFallback), called from apps/cli/src/profile-boot.ts:101 |
O(#closure packages): 261 packages × (resolve probe + existsSync + readFileSync + JSON.parse + link lstat/readlink), all serial and synchronous |
Per-row dynamic import + tsx transform of each package's reachable src/ graph |
vendor/loader/src/config/tree.ts:145, vendor/loader/src/config/entry.ts:280 |
~97 imports in headless, ~151 in web; each is a node_modules walk + esbuild transform under the tsx hook |
| Per-entry package.json read/parse in the typert pass | packages/typert/loader/src/index.ts:315-341 |
one require.resolve + read + parse per composition row |
| Eager network fetches inside the boot window | packages/llm/llm-models-dev/src/index.ts:409-411 (refreshRoutes() unconditional at mount); packages/llm/llm-pi-ai/src/index.ts:448 |
O(#configured routes) HTTP fetches before the first user event |
Double structuredClone of all patches + a config write per boot |
apps/cli/src/profile-boot.ts:103 (writeFileSync of root cordis.yml), composeEntries |
small but serial and on the critical path |
vendor/loader/src/index.ts:68-70seedsenvData = { startTime: Date.now() }— a grep acrosspackages/finds zero consumers. The one boot-timing datum the system produces is orphaned.- No
performance.now/hrtimeexists in any boot-path module. Timing exists elsewhere (hook-run duration inhooks-codex/hooks-claude-code, zstd yield budgeting insession-persistence-jsonl, gate durations inscripts/run-gates.ts) — just not at boot. - Headless mounts no logger service, so loader
showLogoutput is silent: boot is quiet by construction, which also means unobservable.
VS Code rule 1 ("measure first, budgets always") is the discipline this repo lacks most. The feel of "a little bit slow" cannot currently be attributed with data from inside the process.
Already lazy (correct per activation-event thinking):
- Skill catalog: discovery only on first
ctx.skills.list()—packages/skill/skill-filesystem/src/index.ts:182-193,719. - SQLite session query:
openAt: neverby default —packages/bundle/base/cordis.patch.yml:148-152. - Langflow sidecar: child spawns on
start()demand —packages/flowbuilder/langflow-sidecar/src/index.ts:41. - System-prompt assembly and tool-catalog work: per turn, not per boot.
Not lazy:
- Every composition row imports and activates before the first user-visible event; the entry tree
has no deferred bundles and no activation events —
vendor/loader/src/config/group.ts:71fans out concurrently (Promise.allSettled), but readiness is injection-driven, not demand-driven. - The models.dev datasheet fetch and the model-intel scheduler (
packages/subagent/model-intel/src/index.ts:134,221) mount eagerly.
- Shipped path:
apps/clitsdown-bundlesapps/cli/lib/bin.js(per-mode chunks); the installed~/.local/bin/dshexecs it under plain Node — no tsx, no per-module transforms; bare plugin names resolve to each package's"main": "lib/index.js". Acceptance tests:apps/cli/tests/built-bin.e2e.ts,apps/cli/tests/lazy-search-startup.compat.spec.ts. - Dev path:
pnpm dshrunsnode --import tsx/esm apps/cli/src/bin.ts, transforming the whole reachablesrc/graph on the fly against a 229-entrypathsmap. The repo's own Agent Note records measured launch deltas (~0.7s to TUI banner undertsx/esmvs ~1.1s under full tsx; an earlier hook design cost ~440ms ofmakeSyncRequestwait) —.agents/notes/implemented/architecture/2026-07-29-dsh-source-launch-tsx-esm.md. pnpm run demo:cordis/demo:acpstill use full--import tsx(CJS hook on) —scripts/demo-cordis.mjs.
Session.append(packages/core/session/src/index.ts:610-674): validate + push, no I/O on the hot path. O(new data) per event.- Write-behind batching:
packages/session/session-persistence/src/write-behind.ts:45-47clones each event into a pending buffer and flushes on a fixed 200ms window (DEFAULT_WRITE_BATCH_MAX_DELAY_MS = 200,coordinator.ts:30); failed writes re-queue. - JSONL backend: append + fsync with rollback-truncate, zstd frames per batch by default
(
DEFAULT_COMPRESSION = 'zstd'), and packed chunk rows (~60% smaller logs) —packages/session/session-persistence-jsonl/src/index.ts:38,651-679,format.ts:221-224. SQLite backend: single transaction per batch,SCHEMA_VERSION = 15(packages/session/session-persistence-sqlite/src/schema.ts:20). - Durability checkpoints pin flush barriers before first stream chunk and tool bodies
(
packages/session/session-checkpoint-policy/src/index.ts:34-82).
This is genuinely VS Code-grade: append-only, batched, never re-reads prior bytes.
VS Code's lesson was "memory should track the working set, not the file." Here:
- Resume is O(full log), once:
prepareCore(coordinator.ts:892-931) →backend.loadStored→ JSONLreadStableFilereads the entire file into a Buffer and decodes all zstd frames (session-persistence-jsonl/src/index.ts:292-304; explicitly no seek: "JSONL is sequential media", lines 196-200). SQLite hasloadStoredFrom(suffix SELECT,index.ts:225-238) but resume still usesloadStored(all rows) because the live session needs the whole log. - The full log then stays in memory forever:
Session.log(core/session/src/index.ts:427) — every event, including everyassistant/chunkdelta and every compaction replacement copy, for the session's life. Compaction shadows the model surface; it never shrinks the log, memory, or the file (core/session/src/surface.ts:44-47). Session.fromRestorere-validates every seed event (envelope check, surface validation, deep-freeze;core/session/src/index.ts:496-539).
For a multi-hour session with large tool outputs, resume cost and resident memory both scale with total history, not with the working set.
- Per append (when measured):
eventsSnapshotis invalidated on every append (core/session/src/index.ts:663); the next.eventsread doesObject.freeze([...this.log])(line 561) — an O(log-length) shallow copy. TokenMeter's per-event fold readssession.events[state.consumedEvents](packages/llm/token-meter/src/index.ts:160-186), so a measured session pays a full-log array copy per appended event. This is precisely the cost class the piece-tree postmortem warned about ("GC can easily eat your CPU time"). - Per LLM request:
assertNoActiveCompactionruns before the threshold check on everyagent/request-prepared(compaction/compaction-basic/src/index.ts:308vs:318), and its backward scan (inspectCompactionEntryState,region.ts:517-550) only stops early when it finds both a compaction marker and the lastsession/end-seed— which sits at the resume boundary, i.e. near the log's start. Net: a near-whole-log scan per request, plus an O(surface) clone inmeter.measure()and an O(surface) derive rebuild after any compaction replace.
Header/context folds, derived-message nodes, SurfaceManager deltas, the projection registry, and
TokenMeter's fold all process new events only ("each surface node is projected exactly once,
when first seen" — core/session/src/index.ts:736-765). Request assembly uses the in-memory
incremental cache with frozen shared references — agent.ts:491,505 — not a log replay. The
projection-cache cold-read ladder (session-projection-cache/src/index.ts:166-179) already
avoids full-log loads for query consumers; the agent-resume path simply does not use it.
| Holder | Growth | Bounded? |
|---|---|---|
Session.log |
O(total events), incl. all chunk deltas | No — by design (event sourcing); compaction doesn't shrink it |
Session.derived + TokenMeter ReplayState.surface |
O(surface) | Shrinks only via compaction |
jobs-local store (packages/jobs/jobs-local/src/index.ts:102) |
Settled job records (with retained output) never deleted while the owner agent lives — only on owner/service disposal (:471,494) |
No — real accumulation |
Telemetry chunkSeen (session-telemetry/src/coordinator.ts:68) |
One key per step | Dies with session |
| Prepared-session cache, guard chains, subprocess sets, workflow recorder | — | Yes (LRU 5 / 8-entry ring / set-evicted / run-bounded) |
SDK client subscription queues (packages/sdk/client/src/client.ts) |
Unbounded until consumed (standard async-iterator pattern, dropped on close) |
Consumer-paced |
appendToolResult (agent-loop/src/tool-calls.ts:268-289) commits whatever a tool returned,
verbatim, into log + memory + model surface. Caps exist per producer (bash maxOutputChars,
pwsh stream truncation with spill files, jobs outputLimitBytes, fs maxBytes) and post-hoc via
the tool-result pruner — but the pruner runs only when a compaction pass trips
(compaction-tool-result-pruner, base patch thresholdChars: 8192). Until then, one huge output
rides everywhere.
- Workflow scripts run on
worker_threads, one Worker per run, with grace-timed forced termination (packages/workflow/workflow-worker-thread/src/host.ts:149,191-244); code-runtime likewise (packages/code-runtime/code-runtime-worker-thread/src/index.ts:378). - All shell/subprocess work is
child_process.spawnwith detached process groups, bounded output collectors (in-memory tail + spill files), and TERM→grace→KILL teardown ladders (packages/subprocess/subprocess-local/src/spawn.ts:350-361,452; terminal PTYs via node-pty, scrollback throughBoundedTextBuffer—packages/terminal/terminal-bash/src/session.ts:40-75). - LLM streaming is incremental per-chunk:
TextDecoderStream → EventSourceParserStream, oneJSON.parseper payload, deltas yielded as they arrive (packages/llm/llm-deepseek/src/sse.ts:32-38,translate.ts:122), with an idle watchdog and clean mid-stream abort (adapter.ts:230-272). Note: open blocks accumulate their full text until[DONE]with no size cap (translate.ts:138-162) — unbounded only in the sense that a single response is the bound.
- The Cordis contract is uniform: every registration is a fiber effect,
register()returns a disposer, fibers own aDisposableList, and_unloadwalks and disposes everything in reverse with per-disposer error containment (vendor/cordis/src/events.ts:254-260,fiber.ts:203,520,675-687). App shutdown disposes the root fiber (app-boot/src/index.ts:792). getEffects()provides a per-fiber inventory of live listeners — the raw material for leak audits — and tests already assert on it (e.g.packages/extensions/tool-cordis/tests/cordis-lifecycle.spec.ts:44), plus behavior-level "leaked listener would fail" tests.- What does not exist: any process-wide counter,
FinalizationRegistry, or test-global tracker. The repo's own policy (docs/testing.md:9: "Every registry gets an HMR-safety test") is per-suite and opt-in-by-convention — the difference between VS Code'sensureNoDisposablesAreLeakedInTestSuite(fails any suite, everywhere, automatically) and a style guideline.
timeout-policy (declared timeoutMs → structured TOOL_TIMEOUT failure), repeat-tool-reminder
(WeakMap keyed by agent + RECENT_CAP = 8 ring for ping-pong detection), and gate-policy are
rows in the base patch (packages/bundle/base/cordis.patch.yml:377-378,434-478) — ship-always,
config-tuned. State in all three is bounded. No VS Code-style concern here.
- Dev-loop launch (
pnpm dshfrom source): tsx transform of ~97 packages' full source graphs- the serial, synchronous 261-package healing BFS + per-row typert reads — all before the
first model request. The built bin (
apps/cli/lib/bin.js) already skips all of it.
- the serial, synchronous 261-package healing BFS + per-row typert reads — all before the
first model request. The built bin (
- First token of any run: models.dev route fetches sit inside the boot window; boot latency therefore has a network component.
- Resume of a long session: full-file read + full zstd decode + per-event validation +
permanent retention (
§2.2). - Long-running session throughput: O(log) copy per appended event (measured sessions) and a
near-O(log) scan per LLM request (
§2.3) — costs that grow with history even when the working set is small. - A single huge tool output: rides in log + memory + request until a compaction threshold
trips (
§2.6).
Ordered by expected impact on "very, very fast":
- Instrument boot — consume
envData.startTime(or addperformance.now()phase marks) through loader entry import and activation. Rule 1 precedes everything else; today no internal data can confirm which of the above dominates. - Use the built bin for more entry points — the shipped path already exists;
demo:cordis,demo:acp, and dev profiles still pay full tsx (ortsx/esm) transformation. - Make profile healing incremental or cached —
healProfilesModuleFallbackre-verifies the entire dependency closure synchronously on every boot; a mtime/manifest-fingerprint fast path would remove the single largest serial fs cost. - Suffix resume —
loadStoredFromalready exists for SQLite; the JSONL backend documents that it cannot seek, and resume validation + surface fold need the full prefix by design, but the chunk-delta bulk (assistant/chunkruns) is packed precisely for cheap scanning — a resume path that validates headers/surface events and defers chunk payloads is where the piece-tree lesson (memory ∝ working set) would land. - De-essentialize
session.eventsreads in hot folds — a direct indexed accessor (this.log[i]) instead of the invalidated snapshot would delete the per-append O(n) copy for TokenMeter-style consumers. - Reorder the compaction preflight —
assertNoActiveCompactionruns before the threshold check on every request; gating it behind the (cheap) token threshold removes a per-request near-O(n) scan in the common case. - Activation-event the network — models.dev refreshes are natural first-use work, not boot work.
- Mechanize leak detection — a test-global disposable tracker (the repo has the effect
inventory via
getEffects()to build one on) would convert the per-suite HMR-safety policy into a VS Code-style automatic failure. - Bound
jobs-localsettled records — a cap or retirement policy per owner. - A central tool-output ceiling — commit-path cap (or immediate pruner pass) so one huge result cannot ride the whole surface until compaction trips.
- The event write path (batched write-behind, zstd, packed chunk rows, append-only, durability barriers) — better-instrumented than most production systems.
- Incremental projection folds everywhere on the read side except the two hot spots named above; request assembly from frozen shared state, no replay.
- Process off-loading: workers for workflow/code execution, subprocesses with bounded collectors and spill files, PTY scrollback bounds, remote-sandbox backpressure, incremental SSE with idle watchdogs and clean aborts.
- Effect-based lifecycle with tree-recursive disposal, per-fiber effect inventories, and an HMR-safety test policy per registry.
- Bounded state in guards, telemetry, subprocess tracking, and prepared-session caching.
- Boot path:
apps/cli/src/bin.ts,apps/cli/src/profile-boot.ts,packages/boot/app-boot/src/*,vendor/loader/src/*,vendor/include/src/*,packages/typert/loader/src/*,packages/llm/llm-models-dev,packages/llm/llm-pi-ai,packages/bundle/headless,packages/bundle/base/cordis.patch.yml - Session data plane:
packages/core/session/src/index.ts,core/session/src/surface.ts,core/agent-loop/src/agent.ts,agent-loop/src/tool-calls.ts,agent-loop/src/runtime-context.ts,packages/session/session-persistence/src/{coordinator,write-behind}.ts,packages/session/session-persistence-jsonl,session-persistence-sqlite,session-checkpoint-policy,session-projection-cache,session-telemetry,session-title,packages/compaction/compaction-basic,compaction-tool-result-pruner,packages/llm/token-meter - Concurrency/lifecycle:
vendor/cordis/src/{events,fiber,registry,utils}.ts,packages/workflow/workflow-worker-thread,packages/subprocess/subprocess-local,packages/shell/bash-local,packages/terminal/terminal-bash,packages/e2b/*,packages/llm/llm-deepseek/src/{adapter,sse,translate}.ts,packages/guard/*,packages/jobs/jobs-local,packages/sdk/{server,client,protocol},packages/acp/acp,docs/testing.md