r/ruby • u/jasonswett • 15h ago
Call Things What They Are
r/ruby • u/_joeldrapper • 12h ago
We just released the first beta of Phlex 3, which includes a special Ruby-to-Ruby just-in-time compiler, allowing us to optimise performance far beyond what’s possible at runtime.
The compiler starts from what’s actually loaded. It asks each component’s live methods where they were defined, parses those files with Prism and turns them into a syntax tree.
Then it walks the tree and decides what each call really means by asking the running program: is div still Phlex’s div, or has someone overridden it, refined it or mixed something over it? Is that constant still the string it was? Each call we can prove is ours is replaced with a node that just appends text. Everything else is left as it was.
Next comes fusing: neighbouring appends merge, so a run of static elements becomes a single string, escaped and serialised once.
Finally, the tree is formatted back into Ruby, with a source map so that errors point to your original file and line, and this is evaluated in place of the original methods.
I posted more details including some micro benchmark results. You can also see the full release notes on GitHub.
I don’t know if this is going to work or if we’re going to discover some new edge case we hadn’t thought of, but it looks promising so far and it’s been running in production with 465 components for over 24 hours without any issues.
A lesson from maintaining legacy Ruby on Rails apps.