CanadaHonk / porffor

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

tscircuit autorouter running in porffor #206

Open seveibar opened 1 month ago

seveibar commented 1 month ago

File: https://github.com/tscircuit/autorouting/blob/main/algos/algorithm-template-ts/benchmark.ts

Compiled with bun build ./benchmark.ts

Run with porf --module ./benchmark.js

➜  algorithm-template-ts git:(0fc33cb) ✗ porf -d --module ./benchmark.js
RangeError: Maximum call stack size exceeded
    at generateForOf (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:4200:7)
    at generate (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:265:29)
    at generateCode (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:6380:22)
    at generate (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:213:29)
    at Object.generate (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:6206:14)
    at funcRef (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:52:18)
    at generateFunc (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:6371:66)
    at generate (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:210:29)
    at generateClass (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:5848:10)
    at generateFunc (file:///Users/seve/.nvm/versions/node/v22.3.0/lib/node_modules/porffor/compiler/codegen.js:6058:17)
Rob23oba commented 1 month ago

The current implementation of for-of in porffor duplicates code. Nested for-of loops (which appear in the benchmark) make this much worse and causes more instructions to generate than it can handle. The crash here in particular is because porffor uses array.push(...values); to push values into an array, which breaks with too many parameters.