Commit f7bc28d
[ruby/prism] Further optimize ripper translator by not using
Using it seems pretty bad for performance:
```rb
require "benchmark/ips"
require "prism"
require "ripper"
codes = Dir["**/*.rb"].map { File.read(it) }
Benchmark.ips do |x|
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 ruby/prism@553f1675f3) +PRISM [x86_64-linux]
Warming up --------------------------------------
prism 1.000 i/100ms
ripper 1.000 i/100ms
Calculating -------------------------------------
prism 0.319 (± 0.0%) i/s (3.14 s/i) - 2.000 in 6.276154s
ripper 0.647 (± 0.0%) i/s (1.54 s/i) - 4.000 in 6.182662s
Comparison:
ripper: 0.6 i/s
prism: 0.3 i/s - 2.03x slower
# After
ruby 4.0.0 (2025-12-25 revision ruby/prism@553f1675f3) +PRISM [x86_64-linux]
Warming up --------------------------------------
prism 1.000 i/100ms
ripper 1.000 i/100ms
Calculating -------------------------------------
prism 0.482 (± 0.0%) i/s (2.08 s/i) - 3.000 in 6.225603s
ripper 0.645 (± 0.0%) i/s (1.55 s/i) - 4.000 in 6.205636s
Comparison:
ripper: 0.6 i/s
prism: 0.5 i/s - 1.34x slower
```
`vernier` tells me it does `method_missing` even for explicitly defined methods like `location`.
ruby/prism@2ea81398ccdelegate
1 parent 1de6133 commit f7bc28d
1 file changed
+22
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
| |||
201 | 199 | | |
202 | 200 | | |
203 | 201 | | |
204 | | - | |
205 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
209 | | - | |
| 210 | + | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
214 | | - | |
| 215 | + | |
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
219 | | - | |
| 220 | + | |
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
224 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
225 | 239 | | |
226 | 240 | | |
227 | 241 | | |
| |||
0 commit comments