Conversation
eregon
approved these changes
Jan 19, 2026
Member
eregon
left a comment
There was a problem hiding this comment.
Nice, thank you, it seems my performance guess was good then :)
e28cfae to
84f7d3a
Compare
Creating state classes is pretty expensive.
Since they are not modifiable, we can reuse them instead.
Benchmark script:
```rb
require "ripper"
require "prism"
require "benchmark/ips"
codes = Dir["**/*.rb"].map { File.read(it) }
Benchmark.ips do |x|
x.config(time: 10)
x.report("prism") { codes.each { Prism::Translation::Ripper.lex(it) } }
x.report("ripper") { codes.each { Ripper.lex(it) } }
x.compare!
end
```
Before:
```
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]
Warming up --------------------------------------
prism 1.000 i/100ms
ripper 1.000 i/100ms
Calculating -------------------------------------
prism 0.293 (± 0.0%) i/s (3.42 s/i) - 3.000 in 10.248348s
ripper 0.633 (± 0.0%) i/s (1.58 s/i) - 7.000 in 11.055687s
Comparison:
ripper: 0.6 i/s
prism: 0.3 i/s - 2.16x slower
```
After
```
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]
Warming up --------------------------------------
prism 1.000 i/100ms
ripper 1.000 i/100ms
Calculating -------------------------------------
prism 0.486 (± 0.0%) i/s (2.06 s/i) - 5.000 in 10.280413s
ripper 0.635 (± 0.0%) i/s (1.58 s/i) - 7.000 in 11.027169s
Comparison:
ripper: 0.6 i/s
prism: 0.5 i/s - 1.31x slower
```
84f7d3a to
bdde165
Compare
eregon
approved these changes
Jan 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref #3859 (comment). I was interested in how big the impact is and turns out it is a lot.
Creating state classes is pretty expensive. Since they are not modifiable, we can reuse them instead.
Benchmark script:
Before:
After