Closure compiler is inlining a function, but the code size is smaller if that function is not inlined (I only care about code size - this is for JS1k). Can I tell the compiler that I don't want that function inlined?
Edit: Just to explain a bit better, here's my function:
function lineTo(x,y) {
a.lineTo(x,y);
}
where a
in the canvas context. Because there are so many a.lineTo
s in the code, having this function used is worth it. Like this, my code is 1019 bytes (and all the lineTo
s are replaced by a.lineTo
). If I change the function to:
function lineTo(x,y) {
a.lineTo(x,y);
console.log();
}
the new line somehow forces the compiler to not inline this function, which gives me 993 bytes. So if I could get rid of the console.log();
I'd save another 14 bytes.
From the tutorial:
You probably want the second, which is discussed here, but basically comes down to explicitly setting it as a
window
property:For your JS1k submission, you'd just leave the last line off as it's unneeded. note that Closure will still rename the function, but as it starts renaming your symbols with the name
a
and continues from there, it's unlikely to make your names longer overall.You can try it out with the online compiler service. If you paste this in:
...the compiled result is
But if you add
...to the end, the compiled result is: