Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ordinary ResX JSX now becomes HTML template writers through a standalone Rust/Oxc transform of stock ReScript JavaScript. ReScript remains responsible for type checking and JavaScript generation. The server bundler applies native transform edits in memory and emits the application bundle. App source and stock compiler output are untouched; there is no second ReScript compilation or generated ReScript project.
Application integration
In the demo,
bun run build:res:templatesruns stock ReScript once and bundles to.resx/optimized/app.mjs.bun run start:templatesruns that bundle from the existing demo directory./cataloguses normal ReScript JSX with no annotations or alternate component API. The demo optimizes 20 template regions across eight modules.The Bun plugin now owns compiler startup/shutdown, so build scripts use
plugins: [resxBunPlugin()]without manually managing a worker. Unchanged modules remain available to other plugins. Vite/Rollup production integration also has a real build-and-run test, including reuse after a source edit.The native tool is in
compiler/oxc/src/main.rs, the shared adapter iscompiler/oxc-transform.mjs, and the tested Bun integration iscompiler/oxc-bun.mjs. Seecompiler/README.mdfor setup and generated-code examples.What makes it faster
Nested native JSX with literal attributes becomes coalesced static HTML plus dynamic child slots. This removes native element/props allocations and repeated tag/attribute serialization. Writers remain private; dynamic expressions evaluate once, in order, and dynamic children use the existing renderer for escaping, context, and async behavior.
The transform checks scope-resolved imports against approved ResX runtime paths. Mutation, namespace escapes, direct eval, unsupported props, and void elements conservatively fall back. Static text is coalesced during planning without a separate merge pass. Generated names use decoded Oxc symbol/reference information, covering escaped identifiers and nested bindings; writer arguments cannot shadow the runtime import. A persistent Oxc process handles modules; content-addressed caching avoids re-parsing unchanged code. MagicString applies edits and supplies source maps. The in-memory cache retains only the latest source version per module.
The implementation stays local: approximately 470 lines of Rust and 160 lines of adapter/build integration. The design borrows scope-safe generated names from Solid’s SSR template transform and incremental string coalescing from Vue’s SSR code generation.
Measurements
Bun 1.3.14, Linux x64, AMD RYZEN AI MAX+ 395. Three fresh-process baseline/optimized pairs, run serially after builds/tests finished. Each process warms up for at least one second per workload and takes nine approximately 60 ms samples. Values below are medians of process medians. Both modes evaluate the same stock fixture module; the optimized mode transforms it before timing. Output is verified before and after each workload. These are fixture measurements, not a claim that every application becomes this much faster.
Reproduce with
bun bench/compiler.mjsandbun bench/compiler.mjs --optimized. The request workload includes Request/Response and handler work, but no network transport. The simplification produces byte-identical JavaScript for this measured fixture, preserving these results.Build comparison uses identical Bun production bundling with/without the transform, three serial pairs per cache condition. Stock ReScript is already up to date; “uncached” refers to the ResX transform cache, not a clean ReScript build. Native tool compilation is excluded.
Whole build medians, including stock compilation and plugin initialization: 127.71 → 193.34 ms in the empty-cache sample and 138.33 → 141.84 ms with cache. Stock compilation varies substantially between these short runs; the bundling measurements isolate plugin overhead. Bundling now includes automatic compiler initialization. No raw measurement snapshots are committed.
Validation
/catalog,/start, 404 HTML, and catalog CSS, with matching statuses.Remaining scope
This is an opt-in prototype, not a release-ready compiler package. Native binary distribution/install and watch-mode integration still need work. Bun production bundling and Vite/Rollup library builds are tested. Development-server watch/HMR remains unverified. The demo uses stock CommonJS output; the Vite integration test bundles an ESM caller with the real CommonJS framework runtime. Current analysis is local JavaScript analysis: no CMT instruction manifest or cross-module component inlining yet. Typed ReScript analysis can be added later for optimizations that need stronger proofs. Runtime monkey-patching elsewhere in an application is outside the optimization contract. Streaming was not a performance target.