This write-up explains how run-time code generation - effectively using the application as a just-in-time compiler - can speed up a specific Rails pattern: enums. It walks through a practical exchange where a developer wanted to optimize an enum-backed predicate method and shows benchmark runs across plain Ruby and two JIT runtimes (yjit and zjit). Sample output compares create_table timings and a "shippable?" predicate throughput: baseline ~1.7M i/s on CRuby versus ~3.6-3.8M with JITs, and after a focused change in an upstream PR the numbers jump to ~3.1M on CRuby and ~16-18.5M on JITs. The post links to the PR and highlights that code was generated at run time to achieve these gains.
The main conclusions are concrete: prefer static values over dynamic dispatch where possible, precompute or "burn in" constants, and avoid public_send for hot paths because it's comparatively slow. It argues that many performance problems can be solved by improving upstream libraries (especially when they already use code generation) rather than building a bespoke compiler layer inside the app. The practical takeaway is to target small, upstream fixes and to leverage runtime code generation/JIT capabilities to get large performance wins with minimal infrastructure changes.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.