r/ClaudeCode • • 55m ago

Built with Claude Showcase: a Claude Code cloud session ported Terser (JS minifier) to Rust. Output is byte-identical to Terser, 2.6x to 4x faster on my M4. Setup and failures inside

Post image

Repo: https://github.com/erkamyaman/rust-anything

What it is: terser-rs, a module-by-module Rust port of Terser 5.51.4 (parser, printer, scope, mangler, compressor, source maps, CLI, plus a port of acorn 8.15). The `terser` binary is a drop-in for `bin/terser`, and there's a napi addon for `require("terser-rs").minify`.

Setup:

- Claude Code on the web (a cloud session), working in my repo on its own branch.

- The task: port one Terser module at a time, and check each one against the real Terser in Node before starting the next.

- The judge is Rust Anything, my CLI: `record` saves what Terser returns, throws and prints, `diff` replays every case against the Rust, and `gate` only passes at 100%. The agent doesn't decide when it's done.

Expected vs actual (the GIF is a real run, M4, Node 24, -c -m, best of 5):

- moment.js 0.23s → 0.06s (4.0x), lodash 0.32s → 0.09s (3.6x), d3 0.78s → 0.30s (2.6x)

- output byte-identical to Node Terser on all three

- Terser's own test/compress fixtures: 2,607 of 2,607 match

- CLI fuzzing: 29,522 argument vectors, 29,497 identical. The 25 that aren't are listed in the PR (mostly V8 stack-depth limits, plus 4 `sections` input maps the port refuses)

Where Claude got it wrong (written up in issue #924 and docs/pitfalls.md):

- One function matched all 3,985 recorded cases, but those were all JSON values. The real app passes AST nodes, so it crashed as soon as it was switched on.

- The "original" Terser checkout still had one unit switched to Rust from an earlier experiment, so for a while Rust was checked against Rust.

- It reported numbers from its agents' runs as if they were final. The PR now marks which numbers I re-ran from the repo and which I didn't.

Not done: TypeScript parsing, `sections` input maps and a few acorn hooks aren't ported. It's a draft PR, not on npm yet, and only Linux has been tested beyond a smoke run.

Mistakes in detail: https://github.com/erkamyaman/rust-anything/issues/924

Repo: https://github.com/erkamyaman/rust-anything

0 Upvotes

3 comments sorted by

•

u/AutoModerator 55m ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Sorry-Finger-3161 46m ago

2.6x to 4x on minification means my build goes from 40 seconds to 38, and the other 38 are still tsc and webpack doing whatever it is they do.

1

u/erkamyaman 43m ago

Fair. If minify is 3s of your build, this saves 2. The bigger point is the method: an agent ported Terser without changing one byte of output, and the same loop works on your own slow code.