CanadaHonk / porffor

A from-scratch experimental AOT JS engine, written in JS
https://porffor.dev
MIT License
2.83k stars 62 forks source link

Fibonacci example generates unexpectedly large output #173

Open rajsite opened 3 months ago

rajsite commented 3 months ago

The current fibonacci example on https://porffor.dev/ with content:

let a = 0, b = 1;
Porffor.numberLog(a); Porffor.numberLog(b);

for (let i = 2; i <= 45; i++) {
  let t = b + a;
  a = b;
  b = t;

  Porffor.numberLog(t);
}

Compiles out to 323265 bytes.

If I break out some asm.js ideas buried in the back of my head and tweak it like:

let a = 0, b = 1;
Porffor.numberLog(a); Porffor.numberLog(b);

for (let i = 2; i <= 45; i++) {
  let t = b|0 + a; // could alternatively do `+b + a`
  a = b;
  b = t;

  Porffor.numberLog(t);
}

Compiles out to 341 bytes.

Seems like compiled output size would be interesting to track as 262 compliance goes up.

CanadaHonk commented 3 months ago

Yep this is a bug of it including much more built-ins than needed and not doing the best type tracking, should be fixed in next few weeks.

rajsite commented 3 months ago

Couple related observations:

Rob23oba commented 3 months ago

Well, there's not much optimization currently since that's not really the focus right now. In the future such code should compile again to reasonable sizes.

CanadaHonk commented 3 months ago

Still not amazing but the same code now compiles to 74307 bytes instead of the huge size of before.

rajsite commented 3 months ago

Maybe a custom font with built-in syntax highlighting will help with rendering large output a bit. 🤯 Need more porffor wasm in my fonts. 🔥