Skip to content

Frontend: reuse scratch token storage across template substitutions #913

Description

@glennmichael123

Parent: #496. Related correctness work: #911, #912.

Evidence

The existing frozen representative_frontend_templates_tagged_substitutions_{1024,2048,4096} runner on bff189a shows linear instruction growth, but allocation replay at width 4096 reports 8,205 requests and 1,411,152 cumulative allocated bytes per complete parse. The diagnostic used 10 jobs and 3 samples, unchanged workload source, real zig-gc 0285ef8 and zig-regex c60344d; it is not a publication-quality throughput comparison.

Both template paths construct a fresh Parser token array for every substitution using the AST arena. Once a substitution is parsed, its Token structs are no longer needed: AST nodes retain source/decoded payload slices, not addresses of Token structs. Keeping every token buffer until arena destruction adds one allocation per short substitution and retains capacity proportional to the sum of expression tokens.

Root-cause change

Reuse a scratch-owned token list across sibling substitutions of each template. Keep decoded text and AST allocations in the original arena; give nested templates distinct lists; preserve full lex/parse/cover validation and source diagnostics. Release scratch on success and every error path. No grammar-specific fast path, source cache, skipped parse work, or precompiled input.

Gates

  • Lifetime tests after buffer overwrite: decoded identifiers/strings, function source, nested templates, and error tokens.
  • Scratch allocation reuse and spill/growth/OOM cleanup witnesses.
  • Template/context parser and forced tree-walker/VM tests; exact-parent relevant test262 accounting.
  • Clean exact-parent alternating evidence at the existing 1K/2K/4K widths and non-substitution controls. Publish only metrics accepted by the owned evidence tools, retaining raw artifacts and all guard failures.

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