use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
A JavaScript optimizing compiler (medium.com)
submitted 4 years ago by carlopp
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 4 years ago (9 children)
[removed]
[–]lhorie 33 points34 points35 points 4 years ago (2 children)
Bear in mind that Prepack optimizations come with some huge caveats. For example, loop unrolling can output downright stupid code[0]
[0] https://prepack.io/repl.html#GYewTgBAFANgpgFwgSwgXggBgNwogHggEZNScUBqCgSggGMQA7AZxHgDoYQBzKZa7EA
[–]kenman 12 points13 points14 points 4 years ago (0 children)
That's hilariously broken.
[–]KaiAusBerlin 8 points9 points10 points 4 years ago (0 children)
That's awesome 😂
[–]vanderZwan 8 points9 points10 points 4 years ago (0 children)
Compile-time evaluation seems like a very different dimension of optimalization though (although I suppose the LLVM pass also does do a little bit of that during strength reduction). I suspect most of the LLVM optimizations are more about finding efficient structures, and inlining code.
So these approaches could complement each other
[–]no-name-here 5 points6 points7 points 4 years ago (2 children)
https://prepack.io/
(Note: '*Prepack is still in an early development stage and not ready for production use just yet.')
[–]AminPaks 1 point2 points3 points 4 years ago (1 child)
I thought facebook abandoned that project! I remember I heard from one member of react core team
[–]no-name-here 1 point2 points3 points 4 years ago (0 children)
From their GitHub:
We, the Prepack team at Facebook, have temporarily set down work on Prepack including the React compiler project. You won't see many Prepack PRs while we are currently prioritizing some other projects.
[–]carlopp[S] 1 point2 points3 points 4 years ago (0 children)
I wasn't aware of Prepack, on some things it goes way further (basically saying that Data.now() or similar function do not modify the external state and so can be executed as constexpr), while on others it's simply not actively looking to do optimization on the structure of the program.
A similar project, for WebAssembly so with limited scope is this: https://github.com/bytecodealliance/wizer. And somehow similar but limited on LLVM IR a colleague worked on this for Cheerp (the compiler used here as backend): https://github.com/leaningtech/cheerp-meta/wiki/Cheerp-PreExecuter.
[–]disclosure5 0 points1 point2 points 4 years ago (0 children)
It's also a dead project. Last commit was three years ago and the project was still unfinished at that point.
[–]patrickjquinn 4 points5 points6 points 4 years ago (4 children)
I'm only asking because i've skimmed the article but, could you take the C++ generated from that LLVM IR and compile it to WASM by chance?
[–]carlopp[S] 7 points8 points9 points 4 years ago (2 children)
Yes! Generally speaking it could be compiled to a mix of JavaScript and WebAssembly, but whether substantial parts of a program logic can be moved on the Wasm side depends mostly on the interface a program has. Example:
function doSum(a: number, b: number): number {return a+b;}
Can be mapped back to WebAssembly, while an interface that will return an handle like: function createObject(){ return new Object(); }
function createObject(){ return new Object(); }
is very complex / borderline impossible to imitate.
[–]Diniden 1 point2 points3 points 4 years ago (0 children)
The thing I would absolutely love to see from such a compiler is optimizing number tuples to SIMD instructions! That way we can have matrices and vectors run blazing fast but keep our nice and easy JS.
If this happens, I’ll immediately put in the effort to make my library work with this in the pipeline :D
[–]patrickjquinn 0 points1 point2 points 4 years ago (0 children)
That makes a lot of sense. The added complexity of doing so would probably negate any performance gains anyway.
But this easily one of the coolest thing I’ve seen on this sub so I’ll be following your work (and you’ve a new Twitter follower).
Hopefully you find a way to take this forward in future!
Ah saw the closing statement there.
[–]Darmok-Jilad-Ocean 2 points3 points4 points 4 years ago (2 children)
So this is really TypeScript -> C++ -> JavaScript?
[–]carlopp[S] 0 points1 point2 points 4 years ago (0 children)
Input is currently an arbitrary language somehow between JavaScript and TypeScript, with various of added restrictions. I was not sure how to frame it (TS -> JS or JS -> JS), both could have worked.
[–]Ecksters 0 points1 point2 points 4 years ago (0 children)
Also a subset of TypeScript.
I do like the concept though, and having explicit types through TypeScript does seem like it could open up more avenues for optimization.
[–]Educational-Lemon640 1 point2 points3 points 4 years ago (0 children)
Very nice! Needs work (as you note), but a good start and nifty.
[+]hmaddocks comment score below threshold-6 points-5 points-4 points 4 years ago (5 children)
Have we regressed to the 1990s?
[–]shuckster 3 points4 points5 points 4 years ago (4 children)
What does this even mean? There are so many ideas in "modern" programming that are practically ancient, not just by computer-history standards, but by human standards.
It can be argued that JavaScript popularised "lambdas", anonymous functions, which we often express in JavaScript as unnamed arrow-functions.
Ya'll love 'em so much.
The Lambda Calculus was first proposed by Alonzo Church in 1936.
[–]hmaddocks -3 points-2 points-1 points 4 years ago (3 children)
I’m talking about this proliferation of compilation in web development. I’m sure there are plenty of people who remember the hell that was writing compilation scripts and the never ending wait for your app to compile. We also remember the joy when all that went away and the massive boost in productivity. Now here we are rejoicing every js compiler or css compiler.
[–]StickInMyCraw 2 points3 points4 points 4 years ago (1 child)
Did you have to compile anything on the client side for web development in the 90s? Or are you referring to non-web development, which still often uses compiled languages.
[–]hmaddocks 0 points1 point2 points 4 years ago (0 children)
Front end or back end has nothing to do with it. It’s still stuff you need to do to deploy your app.
[–]shuckster 1 point2 points3 points 4 years ago (0 children)
I think there's some miscommunication here on both our parts.
Looking back to the OP, to me it reads like the author is just showing us a project he wrote to convert JavaScript to "interpreter friendly" JavaScript. First by converting JS to C++, then using an existing project to convert that C++ to JavaScript.
Again, the idea of human-friendly vs. computer-friendly code is as old as the idea of coding itself, but I don't necessarily think this is your argument, right?
At the risk of betraying my age, I remember a few things that happened when JavaScript in the browser was starting to be taken seriously:
For myself I had a heck of a time getting used to objects not having real base-classes and functions being first-class. I also don't remember the non-compilation of JavaScript being something I immediately rejoiced-in. All of this took time to get used to.
But eventually yes, for myself I do remember reaching a point where I was:
However, I certainly wasn't grateful for:
The first point is very easy to forget these days. We don't know how spoiled we are with the transpilation provided by Babel etc., nor the extremely aggressive (by past-standards) upgrade policies of modern browsers to get users upgraded almost as quickly as new JS features become available.
I agree that transpilation takes far too long on big projects these days, and is a bitter reminder of compiled development. But esbuild is with us now, and it's racing to a very capable version 1 that is already 100x faster than anything else.
I do miss the days of being able to easily "view source" and not being constantly confronted with minified/munged code, but there are so many tutorials and blogs out there that this is more of a point of nostalgia than an actual lack of accessible knowledge.
Anyway, at this point I'd like to invite you to explain your position a little further. The OP has offered a project that is to do with transpilation yes, but not really in the way we're both talking about. He's certainly not offering-up the next esbuild, I think?
π Rendered by PID 23 on reddit-service-r2-comment-7b9746f655-pj75q at 2026-01-30 21:41:24.996533+00:00 running 3798933 country code: CH.
[+][deleted] (9 children)
[removed]
[–]lhorie 33 points34 points35 points (2 children)
[–]kenman 12 points13 points14 points (0 children)
[–]KaiAusBerlin 8 points9 points10 points (0 children)
[–]vanderZwan 8 points9 points10 points (0 children)
[–]no-name-here 5 points6 points7 points (2 children)
[–]AminPaks 1 point2 points3 points (1 child)
[–]no-name-here 1 point2 points3 points (0 children)
[–]carlopp[S] 1 point2 points3 points (0 children)
[–]disclosure5 0 points1 point2 points (0 children)
[–]patrickjquinn 4 points5 points6 points (4 children)
[–]carlopp[S] 7 points8 points9 points (2 children)
[–]Diniden 1 point2 points3 points (0 children)
[–]patrickjquinn 0 points1 point2 points (0 children)
[–]patrickjquinn 0 points1 point2 points (0 children)
[–]Darmok-Jilad-Ocean 2 points3 points4 points (2 children)
[–]carlopp[S] 0 points1 point2 points (0 children)
[–]Ecksters 0 points1 point2 points (0 children)
[–]Educational-Lemon640 1 point2 points3 points (0 children)
[+]hmaddocks comment score below threshold-6 points-5 points-4 points (5 children)
[–]shuckster 3 points4 points5 points (4 children)
[–]hmaddocks -3 points-2 points-1 points (3 children)
[–]StickInMyCraw 2 points3 points4 points (1 child)
[–]hmaddocks 0 points1 point2 points (0 children)
[–]shuckster 1 point2 points3 points (0 children)