Skip to content

Optimize ripper bounds, and one other small perf tweak#4083

Open
Earlopain wants to merge 2 commits intoruby:mainfrom
Earlopain:ripper-bounds-perf
Open

Optimize ripper bounds, and one other small perf tweak#4083
Earlopain wants to merge 2 commits intoruby:mainfrom
Earlopain:ripper-bounds-perf

Conversation

@Earlopain
Copy link
Copy Markdown
Collaborator

Basically a port of ruby/ruby@c45f781 into ruby

It's quite effective at ~97% hit rate for me. Speeds it up from ~6.77x slower to only 4.07x slower.

For the lexer on_sp it also gives a bit of an improvement: 1.04x slower to 1.10x faster

I guess the class may be universally useful but for now I just made it nodoc. I also didn't look much into the window, it seemed good enough.


Other commit is a small hack to skip redudant pack/unpacking of locations. Prism by default packs locations into a 64bit integer and later extracts start offset / length to create the location. But we know we access nearly all of the locations anyways, so we can request a frozen result to compute them eagerly. It gives about a 4% speed boost.


Benchmark from 2ea8139

@kddnewton
Copy link
Copy Markdown
Collaborator

I don't think I want that generally in parse result. Can you put that into the ripper translator? (Just not sure if we truly want to support that for everyone going forward.)

I see you must have determined unshift wasn't as fast as reassigning and splatting the array. That really surprises me, are you sure that's the case?

@Earlopain Earlopain force-pushed the ripper-bounds-perf branch from 3e8c264 to ee99eee Compare April 20, 2026 19:22
@Earlopain
Copy link
Copy Markdown
Collaborator Author

I don't think I want that generally in parse result. Can you put that into the ripper translator?

Yeah, I can move it. I had it nodoc but that's fine too.

I see you must have determined unshift wasn't as fast as reassigning and splatting the array. That really surprises me, are you sure that's the case?

It's probably not. But it also only happens for what ripper considers void statements. The change is only to make 3e8c264 work, and overall it comes out positive.

@Earlopain Earlopain force-pushed the ripper-bounds-perf branch from ee99eee to c22a6fd Compare April 20, 2026 19:47
Basically a port of ruby/ruby@c45f781 into ruby

It's quite effective at ~97% hit rate for me.
Speeds it up from ~6.77x slower to only 4.07x slower.

For the lexer `on_sp` it also gives a bit of an improvement:
1.04x slower to 1.10x faster

I guess the class may be universally useful but for now I just made it nodoc.
It's a small, somewhat hacky performance boost. Locations are lazy, by freezing the
result they don't have to be pack/unpacked redundantly.
This gives about a 4% speed boost.

Other changes are to not modify the frozen AST
@Earlopain Earlopain force-pushed the ripper-bounds-perf branch from c22a6fd to 9e93bd6 Compare April 20, 2026 20:11
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