Skip to content

tracking(perf): bound storage and protocol read/write amplification #5038

Description

@Astro-Han

Problem

Some Storage and Runtime Host operations process substantially more data than the requested result or the new change requires. Repeated page serialization, full-record output updates, full-store metadata reads, and historical Usage materialization can spend CPU, memory, and I/O on unchanged or unrelated data.

This tracker owns the remaining delivery and measurement work identified by Discussion #4876. It is scoped to read/write amplification in Storage and the Host protocol, rather than every performance issue in Maka.

Scope and relationship to existing work

Use existing issues and PRs for their concrete work. Links here record dependencies and acceptance; they do not create a second implementation or a second owner.

Current evidence

Source inspection baseline: 87797378c. The observations below are code-path evidence, not new production latency measurements.

Repeated encoding and page assembly

Several page builders append one item, serialize the entire candidate page, and discard that encoding after checking its byte length. Examples:

For similarly sized items, cumulative serialization work grows quadratically with the number of items admitted to a page. Existing count/byte caps limit several of these paths; this is not a claim of unbounded whole-history work or a measured user-visible regression in every page builder.

Byte-limit helpers also retain private copies alongside protocol/codec.ts. Consolidation alone is not performance acceptance: measure actual repeated serialization along producer/consumer paths. The transport already accepts EncodedProtocolMessage; extend that seam where applicable rather than adding a parallel encoding path. Raw frame bytes, normalized values, and nested-object budgets are distinct and must not be substituted for one another.

Shell output persistence

ShellRunManager.queuePersist compares the output snapshot with the current record and calls updateShellRun. Storage reads the stored record and serializes the complete next record into record_json.

The full-record operation is confirmed. Its practical amplification remains to be measured against retained-output bounds, flush frequency, and SQLite write/WAL bytes before selecting a representation change.

Existing delivery paths

Work Existing issue / PR Remaining acceptance
Artifact point reads and revisions #4037 / #4874 Verify bounded materialization when unrelated Sessions grow and when the target Session grows; preserve revision consistency and cross-process visibility.
Batch artifact cleanup during Session retirement #4038 / #4984 Verify batch work avoids repeated whole-store guard scans while preserving physical deletion safeguards and retryability.
Revision-consistent bounded Usage reads #4058, #5019 / #5023; related UI work #4531 / #4539 #5023 is currently a design-only draft. Resolve its Storage/query boundaries, then measure SQL scan/sort work as well as application decoding and transfer. UI pagination alone is insufficient.

Delivery checklist

Already changed; do not reopen from the old inventory

Deferred questions

  • Owner-lock/control-directory cleanup requires proof that removal preserves mutual exclusion; coordinate with fix(runtime-host): reap stale Runtime Host control directories #4712. Do not treat unlinking lock files as an ordinary cleanup optimization.
  • Usage retention after Session deletion is a product-policy decision, not permission to delete historical records as part of a performance fix.
  • Other tables without retirement paths are not automatically implementation tasks. Add work only when growth or an operational obligation is established.
  • A repository-wide CI ratchet or mandatory exception ledger is not a prerequisite for the first fix and is not approved by this tracker.

Acceptance

For each delivered path:

  1. Name the real producer, authority, and downstream consumer. Measure through that path rather than only benchmarking a helper.
  2. Compare the same workload on explicit before/after commits. Vary the relevant dimension: page size, target history, unrelated records, retained output, or retired Session count. Include a cold/warm distinction where relevant.
  3. Report applicable rows scanned/decoded, serialization work, retained memory, write/WAL bytes, and elapsed time. For timing comparisons, use repeated runs and report median/p95; distinguish synthetic measurements from production observations.
  4. Preserve UTF-8 byte budgets, completeness/cursor semantics, revision consistency, atomic durable facts, and retry/restart behavior relevant to the changed path. Retain focused behavioral tests that fail on the replaced behavior.
  5. Do not accept moving a full scan from reads to every write, materializing everything behind a paginated API, or adding a second durable authority as a reduction in amplification.

Completion means each delivery item has a verified result or a documented, evidence-backed scope decision. It does not mean every read is constant-time, every historical row is deleted, or the separate user-experience budgets in #4677 have been met.

AI assistance: Codex helped inspect current source and draft this tracker under maintainer direction.

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions