4 ms·
A lot of time (runtime and profiling/optimization) is spent here on looking up variables by name at runtime. Even in an AST, you can fully resolve variable refe
by ghusbands 4y ago
A lot of time (runtime and profiling/optimization) is spent here on looking up variables by name at runtime. Even in an AST, you can fully resolve variable references at parse time to an integer index into the environment/stack. You typically want to resolve them, anyway, so you can catch references to undefined variables.
- dvko 4y agoHey, author here. You're absolutely right, good observation! When writing this post I had actually already moved on towards a compilation step (into bytecode + VM stack machine) where variables are obviously referenced by index. After that (while going back to write this post) somehow traversing the AST while not immediately evaluating it did not feel like tree walking to me. But it obviously still is... Seeing just how slow looking up variables by their name is, I have a feeling this probably amounts to the biggest performance improvement that the bytecode + VM brings to the table (it's ~3 times faster than the AST walker at the time of writing). Especially as there do not seem to be that many cache misses (at least on my hardware) already, sub .2%. Anyway, thank you for your $.02!