ast is being modified by hoist
See original GitHub issueIs there a way to avoid ast modification? Because my code runs pretty slow because of multiple acorn.parse
, so I created a single ast by running acorn.parse
one time and run the same ast multiple times. That’s what I do in JS-Interpreter and is pretty viable as ast is not modified in any way, but keeping all the state in a different object (which I delete or recycle, depending on situations).
I like this interpreter a lot, but I’m having problems implementing it as it always need a new ast, which I create with another acorn.parse
, because the ast is modified while running, so here “ast caching” is not viable. This makes this interpreter way way slower than JS-Interpreter (actually sval is way faster when interpreting the JS (about 8 times), but globally is slower if you do a lot of runs with the same code).
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Yes, sval will modify ast when hoisting, but just move the function declarations to the top of the scope. No any other changes on ast except this.
After finish compile_ir branch, I will expose APIs for caching the bytecodes. Then you can just parse the code once, get the bytecodes, and run the bytecodes multiple times, like:
That’s amazing! Thank you!
I have one related question: in my project I have a case where I need to evaluate just part of ast and get result of it.
run
acceptsProgram
(hoist
requires it at least) and can provide output only viaexport
. Probably you can give me an advice how can I evaluate part of code and get latest values from the stack?Currently for MVP I used very hacked solution:
where
runAST
skipshoist
. In near future I will need to rewrite it into more robust solution, so if you can give an advice it would be awesome.