Skip to content

shell/syntax: avoid copying ambiguity probe tails - #820

Merged
ewhauser merged 2 commits into
mainfrom
ewhauser/avoid-ambiguity-tail-copy
Apr 2, 2026
Merged

ewhauser merged 2 commits into
mainfrom
ewhauser/avoid-ambiguity-tail-copy

Conversation

@ewhauser

@ewhauser ewhauser commented Apr 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • avoid copying the full unread source tail when resolving (( ambiguity probes
  • add a shared replay buffer so the arithmetic and subshell probes can read ahead lazily from the same source stream
  • detach the real parser from the replay buffer once the ambiguous construct is parsed so the rest of the file reads normally

Why

The ambiguity probe previously materialized the full unread tail of the file just to let both probe parsers inspect the same bytes. On larger files this added a large copy-heavy allocation path in the parser hot loop.

Impact

  • BenchmarkParseBenchmarkFiles/nvm before: 4358907 B/op, 46871 allocs/op
  • BenchmarkParseBenchmarkFiles/nvm after: 3868294 B/op, 46795 allocs/op
  • timing improved in the clean before/after run used during development, but later reruns were noisy after long validation, so the allocation reduction is the primary measured claim here

Validation

  • go test ./shell/syntax
  • make lint

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3d70e6fc9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread shell/syntax/parser.go Resolved
@ewhauser
ewhauser merged commit fbc4d26 into main Apr 2, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/avoid-ambiguity-tail-copy branch April 2, 2026 04:19
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