Skip to content

Improve parser and interpreter performance#15

Merged
danielgtaylor merged 2 commits intomainfrom
codex/perf-opportunities
Apr 24, 2026
Merged

Improve parser and interpreter performance#15
danielgtaylor merged 2 commits intomainfrom
codex/perf-opportunities

Conversation

@danielgtaylor
Copy link
Copy Markdown
Owner

Summary

  • Reduced allocations in the lexer, parser, and interpreter hot paths.
  • Added focused benchmarks to track common expression cases and internal helpers.
  • Optimized slice-length handling and primitive equality checks to avoid unnecessary work.
  • Kept behavior stable with coverage updates in the existing tests.

Testing

  • go test ./...
  • Benchmarks run locally for the common slow and cached expression cases, plus new internal microbenchmarks.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on improving performance in the expression engine by reducing allocations and adding benchmarks to track key hot paths across lexing, parsing, and evaluation.

Changes:

  • Reduced allocations by reusing lexer token storage and avoiding interface indirection in parser construction.
  • Added fast paths for slice .length evaluation and primitive equality checks.
  • Introduced internal benchmarks to measure common expression/utility performance.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
typecheck.go Reuses shared option parsing to avoid repeated option scanning.
parser.go Avoids interface calls when using the concrete lexer; supports generic lexers as fallback.
lexer.go Reworks token allocation/caching and avoids per-token rune counting in hot paths.
interpreter.go Adds bound-normalization helpers and a fast path for slice .length.
functions.go Adds a fast-path switch to avoid reflection when resolving non-lazy values.
expr.go Centralizes option parsing and constructs lexer/parser/interpreter/typechecker with fewer allocations.
conversions.go Adds fast paths for deep equality of numbers/strings/bools (including lazy funcs).
benchmark_test.go Adds focused internal benchmarks for lexer, lazy-value resolution, and equality checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danielgtaylor danielgtaylor merged commit 8638660 into main Apr 24, 2026
5 checks passed
@danielgtaylor danielgtaylor deleted the codex/perf-opportunities branch April 24, 2026 00:15
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.

2 participants