I wonder if putting all String literals in constants improves performance? I should probably read Ruby Under The Microscope... patshaughnessy.net/ruby-unde…
2
0
0
Constants aren’t constant so using them over frozen string literals will actually be slower as they require a lookup under the hood. When in doubt benchmark/ips
1
0
3
Ruby constants are actually constant in JITed code in TruffleRuby. A frozen string literal is always constant, so that's as good or better if the implementation does not fold Ruby constants.
1
0
1
So, to get the idea, you optimize to return the possibly mutable object saving a constant lookup, and invalidate/refresh that optimization if there's const removal + set again (as in "reloading"), or re-assignment?
2
0
1
Yes, the JITed is invalidated/deoptimized when the constant is reassigned/removed, and gets recompiled later with the new value (if called enough times)
1
0
1
Great to know, thanks man!

10:37 AM · Jan 17, 2021

0
0
0