Skip to content

shell/syntax: benchmark and optimize parser - #815

Merged
ewhauser merged 3 commits into
mainfrom
ewhauser/parser-benchmark-cpu
Mar 31, 2026
Merged

shell/syntax: benchmark and optimize parser#815
ewhauser merged 3 commits into
mainfrom
ewhauser/parser-benchmark-cpu

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • add an nvm.sh parser benchmark fixture and benchmark coverage under shell/syntax
  • reduce parser allocation churn in source-tail handling, raw-word parsing, paren ambiguity probing, and simple-command separator tracking
  • add scalar assignment fast paths in callExpr to cut CPU and allocation overhead on common foo=bar cases

Why

The new nvm.sh benchmark made the parser hot spots concrete. Allocation profiles were dominated by parser construction and source slicing, and CPU profiles still showed overhead in separator bookkeeping and assignment-candidate parsing.

Impact

On BenchmarkParseBenchmarkFiles/nvm, the latest controlled benchstat comparison versus the pre-CPU-pass state was:

  • sec/op: 7.879 ms -> 5.973 ms (-24.19%)
  • B/op: 4.195 MiB -> 4.143 MiB (-1.22%)
  • allocs/op: 54.97k -> 46.86k (-14.75%)

Overall from the original baseline to the current parser:

  • sec/op: 10.173 ms -> 5.973 ms
  • B/op: 19.087 MiB -> 4.143 MiB
  • allocs/op: 56.46k -> 46.86k

Validation

  • go test ./shell/syntax
  • make lint
  • env GOMAXPROCS=1 go test ./shell/syntax -run '^$' -bench 'BenchmarkParseBenchmarkFiles/nvm$' -benchmem -cpu 1 -count 15
  • benchstat /tmp/gbash-benchstat.7SxhXk/current.txt /tmp/gbash-benchstat.7SxhXk/cpufix.txt

@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: d510391ac6

ℹ️ 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
@ewhauser
ewhauser merged commit ddcd090 into main Mar 31, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/parser-benchmark-cpu branch March 31, 2026 00:29
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