Skip to content

Optimizations#4006

Merged
Earlopain merged 28 commits intomainfrom
perf
Mar 18, 2026
Merged

Optimizations#4006
Earlopain merged 28 commits intomainfrom
perf

Conversation

@kddnewton
Copy link
Collaborator

@kddnewton kddnewton commented Mar 17, 2026

This branch has a ton of optimizations, broadly grouped into:

  • Splitting up functions that would reallocate if they need more space into fast paths and slow paths, with the fast path being static inline in the header so it gets inlined into callers.
  • Adding a bloom filter to local scopes so that it's faster to reject locals that are not found.
  • Having the lexer scan the value of small integers so for integers < 2**32 we only scan them once.
  • Building SIMD and SWAR paths through our custom strpbrk, and then caching the lookup tables that we build for those function calls so that in repeat calls (like when lexing strings, regexps, and list literals) we do not have to recompute them.
  • Lowering the threshold for switching the locals table over to a hash from 9 to 5.
  • Adding SIMD and SWAR paths through scanning identifiers for ASCII.
  • Making some fast paths through parser_lex_magic_comment because it shows up shockingly high in profiles.
  • Putting a lot of the parser metadata into its own arena, as opposed to ad-hoc malloc/free pairs.
  • Changing the constant pool to use a hash function based on wyhash that goes word-at-a-time as opposed to byte-at-a-time.
  • Putting the contents of the constant on the constant bucket (this would seem like a net negative for memory, but because we resize more appropriately now and its backed by the parser arena, it's kind of a wash).

With all this in place, I'm seeing about 22% speed gains, using about the same amount of memory.

@headius
Copy link
Contributor

headius commented Mar 17, 2026

Very nice. I wonder what the impact will be on the WASM build performance. I'll try to get that stuff more finalized today and into CI.

Earlopain and others added 2 commits March 18, 2026 08:40
ruby/ruby@968b999

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
ruby/ruby@5026acf

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
@Earlopain
Copy link
Collaborator

ruby/ruby#16418 is already merged. I pushed up the unique commits from that PR and also ruby/ruby#16423, it's back in sync now

@Earlopain Earlopain merged commit 93542e6 into main Mar 18, 2026
67 checks passed
@Earlopain Earlopain deleted the perf branch March 18, 2026 09:45
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.

3 participants