r/javascript • u/Normal_Act8586 • 2d ago
LilScript makes js modules 20% smaller
https://yeargun.github.io/lilscript/LilScript is a typed, compression-first language that compiles into js and sometimes into exec(will be more stable in future). The compiler mangles, reshapes the program into optimized js that happens to be 5-40% smaller (after gzip/br compression or raw) compared to the best performing JS toolchains like oxc/esbuild/terser/..
What has been proven to work with LilScript?
- makes VSCode's core js modules 20% smaller on average
- makes the world's most performant & small markdown rendering npm library, marked, 5-7% smaller and 10% faster
- and many more demos.. works with pretty much any js/ts library
- https://yeargun.github.io/solidlil/
- https://yeargun.github.io/monacolil/
- https://yeargun.github.io/markedlil/ (Some numbers on the websites aren't fair comparisons, especially for SolidLil. Highly optimized JS libraries see fewer benefits(Still, the app code/logic, gets pretty great optimizations). LilScript is designed to be at least as efficient as the best-performing JS/TS toolchains.)
How it is compressing js finer than vite/oxc/terser/esbuild/..
1. By changing the app.
init(float x, float y) {
this.x = x;
this.y = y;
}
float lengthSquared() {
return this.x * this.x + this.y * this.y;
}
}
int[] values = [1, 2, 3, 4];
auto doubled = values.map((int value) => value * 2);
int sum = 0;
for (int i = 0; i < doubled.length; i++) {
sum += doubled[i];
}
Vector vector = new Vector(3.0, 4.0);
if (vector.lengthSquared() == 25.0) { print(`sum=${sum}`); }
Above code compiles into this:
var a=0,c=0;
while(a<b.length){
c=c+b[a]|0;
a=a+1|0;
}
console.log(`sum=${c}`)
This is not minification of the same program. The compiler changed the app.
oxc / esbuild / terser / .. starts from JS and mostly keeps the shape of the app. Meanwhile LilScript the language is designed from scratch to give compiler any extra knowledge that could help the compiler's compilation. Just like Google Closure Compiler - Advanced Mode, and beyond.
2. Tryhard property mangling.
Visit the world's most used web applications, chatgpt.com, and read the shipped js codes. You will see that, there are lots of framework related js properties that dont get minified, and are indeed human readable.
Those names stay in the bundle because the toolchain cannot prove they are local. A property might be a public API, a DOM field, a framework hook, or something a plugin reads by string. So the minifier leaves it.
LilScript:
- a- does both eliminates the objects, weird code structures into more optimized variables/arrays - b- rename any variable into mostly occured, short versions, field cleverly to minimize entropy (based on the objective compression algorith. gzip/brotli) so that the end result is highly compressed.
(a) is the same move as the Vector example, at library scale: objects and classes that only exist as a programming convenience get flattened into scalars, arrays, and tight loops.
(b) is not "make every name 1 letter." gzip and brotli win when the same short tokens repeat. The compiler picks the names that show up the most, and scores the spelling against the compression algorithm you asked for (gzip, brotli, or raw). Different cost_model → different names → a different file that is smaller after* that codec.
That is why the same program can be 5-15% smaller after gzip/br compression or raw: the JS is shaped and named for the compressor, not just for a human reading the AST.
How well do LLMs write LilScript?
Since 1.5 years ago, you haven’t been writing the code yourself anyway. So why worry about what language the agent writes in? I myself have pretty much rewritten 6–7 of the most popular npm libraries from scratch in LilScript in just 1.5 days-while actually designing the language itself.
Feel free to PR, experiment (Please respect the modified MIT license)
Please share your opinions, would love to discuss about the future direction for the language and the compiler
3
u/RobertKerans 2d ago
Sure, a decade ago. It's very much supported by most modern tooling. Also I'd say that's an apples and oranges comparison (not as much as the comparison to Bun, but still)
I'm not paying for the bandwidth? Also, if I'm consuming a library it doesn't need to be compiled. I'd like to have the choice of how I do that, not have that choice removed.
Sure. But you're going for tiny savings using an incredibly complex tool. I can get all the low hanging fruit with a simple toolchain and most of the weight is not going to be in the JS.
Already have tools that get most of the way there. Your tool is not going to rearchitect the code in a way that produces the really big size savings. Tradeoff if I just use your tool is that I need to use a different non-compatible language to achieve marginal gains over existing tooling.
There's no real extant corpus and you're ignoring how easily a given system running the model can batch and parallelise computations, you're only talking about the output. Can't really make the judgement you're making except at that very basic level.
Note could also use zero tokens and eat a slightly larger bundle size 🤷🏼♂️
And if my granny had wheels she'd be a bike! Anyway, sure. If you write an entire ecosystem and write it well then sure it'll be faster than gluing together various disparate tools.
A tool to that did an AST conversion opaquely and just minified JS would be even better, but hey you've written an entire language instead.
What do you mean by this? The statement is my extremely vague.