Skip to content

perf(string): repeated immutable prefix + number materializes separate flat strings; measure prefix-sharing opportunity #11745

Description

@proggeramlug

Problem and measured evidence

Each document node creates a distinct string from the same long immutable prefix plus a seed number:

const TEXT = 'A collaborative document revision contains paragraphs, comments, edits, and history. '.repeat(3);
// DocNode constructor:
this.text = TEXT + seed;

Measured 2026-10-01 on macOS arm64, Perry main d40ed1a47019bcae547819ebb5756bcd96ba1057 (v0.5.1655), with matching compiler and runtime archives. This snapshot already includes #11645. These are diagnostic probes; no compiler/runtime fix was applied and the original comparison remains unchanged.

Three external 8-second stack captures at 1 ms (19,648 main-thread observations) attribute 8.33% inclusive / 7.22% exclusive observations to js_string_concat_value. This includes formatting and flat-string construction; it does not isolate prefix copying from numeric conversion.

A separate explicit-full-GC census with the cache populated reports approximately 3.08 MiB of strings out of 5.16 MiB reachable tracked heap data (largest live category), with 10,920 DocNodes. Census scheduling/observer allocations differ from the ordinary run. No shared-prefix or rope implementation was benchmarked.

Distinct from existing tickets

Track the remaining opportunity to reduce repeated immutable-prefix materialization/copying where semantics permit. A shared immutable prefix/cons representation is one possible approach; a rope architecture is not a required solution.

Next measurement and acceptance

First isolate numeric formatting, result allocation and prefix-copy cost with varying prefix lengths and equivalent outputs; the 8.33% figure must not be claimed as copying alone. Then measure any candidate against the unchanged cyclic workload, including downstream .length, charCodeAt, indexing/traversal and GC cost, plus retained/released strings.

Preserve independent string values, Unicode/WTF-8 joins, conversion/evaluation order, equality and GC lifetime semantics. Report end-to-end CPU, peak RSS and live string bytes; avoid trading cheaper construction for greater downstream cost without making that trade explicit.

Complete unchanged workload and method: #11743.

Evidence in the project-comparison workspace: demo/results/stress/perry-profile/summary.md, profile-manifest.json, cpu-summary.json, experiment-summary.json, experiments.json, gc-diagnostics.stderr, nursery-4-gc-diagnostics.stderr, census.jsonl, vmmap-*.txt, and the original/typed-receiver makeTree disassemblies. These paths are local artifacts, not publicly hosted links.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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