←
amlug.eth6,886 posts
amlug.eth avatar

amlug.eth

@realamlug

Jesus follower. Husband. Dad of 3 boys, 1 girl. Building Perry - TypeScript compiled to native binaries. No Electron. 🇩🇪

◷ Joined January 2021▧ 572 Photos and videos
amlug.eth avatar
amlug.eth@realamlug·Oct 30

Perry Update: Compiling JavaScript/TypeScript is complicated! How Perry compiles JavaScript and TypeScript to a native binary, and why the hard part isn't the code generation. The pipeline (image): 1. SWC parses your .js/.ts and its dependencies from node_modules. 2. The AST becomes perry's HIR, a high-level intermediate representation. 3. HIR transforms: closure conversion, async/await lowering, inlining. 4. LLVM lowers the HIR to machine code for the target. 5. The system linker links the object files with perry's runtime (including a generational GC) and the native libraries the program needs. The result is one self-contained executable. No JIT, no VM warm-up. The hard part sits between steps 2 and 4. At every o.x and every f(a), the compiler must decide before the program runs: one load at a fixed offset, or the general property lookup (find the layout, search it, walk the prototype chain). A JIT watches the program and guesses; an AOT compiler has to know. TypeScript types can't decide it. They can be wrong (as, any, stale .d.ts); they say what a value may be rather than where its fields live, and most npm code ships without them. Trust a wrong type, and you read the wrong slot. So the rule is: types pick the lowering, shapes prove the semantics. This is also something no other JS/TS AOT compiler does yet. That's what perry's whole-program facts do (the lower half of the image): - Per-unit facts: every module is cut into units, cycles of declarations, and each unit is analysed for object layouts and for what its functions read, keep, call, and change. - Contracts: each unit publishes what others may rely on, e.g., "Circle has r at slot 0, and nothing adds keys to it". - Census: one program-wide check of which layouts anything can break (delete, computed-key writes, stores through unknown values). - Rounds: affected units re-solve until nothing changes. Proven: p.x is one load at a fixed offset, and c.area() is a direct call behind a single class check. Not proven: the general lookup, which is always correct. Missing facts cost speed, never correctness. Where it stands (2026-10-30), on the TypeScript compiler's own source: 20,028 sites proven per unit, up from 390 before 2026-10-25. tsc's checker serves as an independent oracle, never as input: its types pin down 42,313 sites, leaving a 22,865-site worklist. Still open: unit edges (Richards: 37 sites per unit vs 1,673 whole-program), stores into built-in prototypes, compile cost. What compiles and matches node: the AWFY benchmarks, the TypeScript compiler, commander, fastify, qs, yargs, marked, effect and the 22-program js-compiled suite. Small programs, like benchmarks, etc., work out exactly the way we need them to. The difficult piece is compiling entire programs, including their NPM dependencies. This is still ongoing, but progress is going well. :)

Post attachment
amlug.eth avatar
amlug.eth@realamlug·Nov 11

Nice! For Perry to compile Effect properly a small change would have been helpful. So I suggested a way to do that and the AI for Effect implemented it as I suggested and it just got merged. Thanks @EffectTS_ 👍 This allows better optimization for AOT. github.com/Effect-TS/effect/…

amlug.eth avatar
amlug.eth@realamlug·Nov 11

I've been using X for 17 years ... And I still don't care about how to share tweets or posts and whether or not there is a screenshot or not. Thought y'all would like to know that about me. 😅

amlug.eth avatar
amlug.eth@realamlug·Nov 9

There are more cross-platform frameworks than cross-platform apps soon lol.

amlug.eth avatar
amlug.eth@realamlug·Nov 8

This one hit a nerve lol. The point was simply: choosing a "native/fast" language doesn’t make your software fast. A badly written C++/Rust app can easily lose to a well-written Node app. Architecture, algorithms, and I/O matter far more than the language for 99% of what we build. Not to forget the compiler. ;) Yes, lower-level languages give the compiler more to work with, so the ceiling is higher. But most apps aren’t drivers or game engines. They never get anywhere near that ceiling.

Rust is not faster than JavaScript! Rust is also not faster than C++. The compiled binary code might be faster than the compiled binary code of either of the others. But that's a compiler question, not a language question. Some languages make it easier to compile to performant code than others, but the trade-off is in the language itself. Don't confuse language with execution.

Nathan Lugado avatar
⟳ amlug.eth retweeted
Nathan Lugado@NathanLugado·Nov 7

I think he's trying to highlight that compiler tech has advanced so rapidly that a language's design may no longer bound performance. In my own experiments, you can get JS to run faster than idiomatic rust with lower peak memory. Of course, expert rust still wins

amlug.eth avatar
amlug.eth@realamlug·Nov 7

Rust is not faster than JavaScript! Rust is also not faster than C++. The compiled binary code might be faster than the compiled binary code of either of the others. But that's a compiler question, not a language question. Some languages make it easier to compile to performant code than others, but the trade-off is in the language itself. Don't confuse language with execution.

amlug.eth avatar
amlug.eth@realamlug·Nov 7

Why are devs so religious? Why do you care about what other people use in _their_ stack? Does it help _you_ if someone _else_ is using Rust in _their_ project? 😅

amlug.eth avatar
amlug.eth@realamlug·Nov 6

To develop Perry I develop a lot in Rust. So, to have a good dogfooding project I developed tuichess.dev Two interesting things: 1. It's freaking fun to develop games in Typescript. Development is fast and AI is really good. Rust development is so slow compared to that! 2. Perry will provide an easy way to convert three.js games into **fully native games**! More about that soon!

amlug.eth avatar
amlug.eth@realamlug·Nov 4

Not yet published as the 3d version, coming together with the rest. :)

amlug.eth avatar
amlug.eth@realamlug·Nov 4

So I updated the TUI version to render nicer. 3D in Terminal (Ghosty, etc., GPU-supported). 😅 My goal is to develop this into a nice Perry project that will be published on all app stores and have a nice 3d version. Already developed as a standard Three.js app that will then turn into a Perry + Bloom Engine app. Nothing special, but a good case to test the compiler. :)

Post attachment

Weekend project: chess right beside Claude Code ♟️ /plugin install chess --marketplace skelpo/chess /chess Board in a pane, ask Claude about your position, or play people online with clocks. The engine is plain TypeScript compiled to native with Perry, ~8 MB, and starts in 10 ms.

Post attachment
amlug.eth avatar
amlug.eth@realamlug·Nov 3

I find it kinda entertaining that I am having serious and great conversations about companies using Perry (bigger companies) in X chat and Discord. Try explaining that to my parents 🤣

amlug.eth avatar
amlug.eth@realamlug·Nov 3

Remember when Claude would suggest you "take a break and pick things up later"? Seems ages ago and I'm so glad it no longer does that.

amlug.eth avatar
amlug.eth@realamlug·Nov 2

Weekend project: chess right beside Claude Code ♟️ /plugin install chess --marketplace skelpo/chess /chess Board in a pane, ask Claude about your position, or play people online with clocks. The engine is plain TypeScript compiled to native with Perry, ~8 MB, and starts in 10 ms.

Post attachment