Sprinting, Heads Down
My last post went up on June 9. I didn't stop writing on purpose. The work just kept being more interesting than writing about it, and every week I told myself I'd write once the next milestone landed. Five months went by.
My original goal for trails, my Rails port in TypeScript, was ActiveRecord parity. That goal is basically met, so the goal changed to all of Rails. This post covers where that stands.
The numbers
Since June 9:
- 6,899 merged PRs to trails, out of 9,828 total. More than two thirds of the project's PRs were merged in the last five months.
- About 13,900 stories closed and 176 RFCs (epics) closed in the tasks repo.
- Packages went from 16 to 49.
- Under
packages/, roughly 1.08 million lines added and 600,000 deleted.
The PR count needs the usual caveat: coding agents write most of these PRs, and a PR count measures throughput, not value. What I trust more is the parity number, because a script computes it and I didn't write it to make myself look good.
Why 49 packages
Most of the new packages aren't Rails gems. They're the gems Rails depends on.
When I started on ActionMailer, I found it needs mail, which needs
mini_mime and net-smtp. Solid Queue needs fugit, which needs raabro
and et-orbi, and et-orbi needs tzinfo. Active Storage needs marcel,
mini_magick and image_processing. Railties needs thor, rake and
zeitwerk. Each one either gets ported or gets stubbed with something that
behaves differently from what Rails expects. A behavioral difference in a
dependency eventually turns into one in the framework.
So they got ported. Many are small and now sit at 100% API parity: fugit,
chronic, raabro, et-orbi, net-smtp, mini_mime, erubi, i18n.
mail is at 98%.
The scope just grew again. I pulled Hotwire in, so a generated trails app
should ship with Turbo frames, Turbo Streams broadcast over Action Cable, and
Stimulus controllers, the same as a new Rails 8 app. That means trails now
does frontend JavaScript packaging too. Rails uses importmap and propshaft
for this. Trails uses Vite, by porting vite_ruby and vite_rails, and
pulls the JS libraries from npm as-is. That work has only just begun.
The parity gates
In June, the parity scripts mostly answered one question: does ActiveRecord have the methods Rails' ActiveRecord has? Today they measure every Rails gem and every ported dependency, and they check much more than whether a method exists:
- Methods and files: 27,511 of 29,177 Ruby methods have a TypeScript counterpart in the matching file (94.3%). The data layer is at 8,848 of 8,864. ActiveRecord, counted together with everything it pulls in, is at 99.4%.
- Arity: 99.7% of matched methods take the same number of arguments.
- Parameter names: 99.8% use Rails' own identifiers.
- Inheritance: 96% of class hierarchies match.
- Literals: 2,357 default values and constants compared, 0 differ.
The remaining 5.7% is mostly long tail in dependencies (nokogiri, tzinfo,
racc). The Rails gems themselves are close to done.
Running it for real
Parity scripts show that the shape matches. They can't show that it works. For that I have trailmap, a trails app that helps manage trails development. It owns the task database, serves the dashboard, and runs the stats sync as a job that sends mail when something breaks.
That's the first time jobs, mailers and websockets (through rack) have run in a real environment and not just a test suite, and they've found bugs no test caught:
trails/alldidn't load the ActionMailer railtie.- Setting
queue_adapter = :solid_queuedidn't find the adapter. - SQLite's busy wait blocked the event loop.
trails serverdidn't await server blocks.
Every one of these had a passing test suite behind it. 100% parity tells you nothing is missing. It doesn't tell you the pieces work together, and only an app can tell you that.
Performance, and a compiled Rails
I've also started on performance. The first benchmark is the $12 server challenge: I took a Rails 8.1 submission and ported it to trails file for file, then ran both on the same pinned core. Rails with YJIT does about 1,200 req/s on a single-post read. In the latest run, trails on Node does 715. Trails is slower, but the gap is now measured, and it shrank between runs.
The other experiment is compiling a trails app to a native binary with
Perry, an ahead-of-time TypeScript compiler. The
app is plain trails new output plus one trails g scaffold, with nothing
written to suit the compiler. It just got its first successful scaffold
running: a compiled binary serving the generated CRUD over HTTP. That's a
first look at a fully compiled Rails.
What's next
First, code cleanup, verification and planning:
- Fix dropped promises.
- Redesign trailmap.
- Give a demo talk at GR Web Dev.
- Upgrade from Rails 8.0.2 to 8.0.5.2, the latest patch release.
- Port Hotwire: Turbo, Stimulus, and Vite for the JavaScript.
- Publish an npm release.
After that comes the upgrade to Rails 8.1.4.1, then a docs site, and then a public launch.
Comments
Leave a Comment