3 ms·
> Walking a tree doesn't seem like that much of a performance penality... It really is. At the level of a language interpreter, cycles count and things like ca
by munificent 8y ago
> Walking a tree doesn't seem like that much of a performance penality...
It really is. At the level of a language interpreter, cycles count and things like cache misses become important. Bytecode keeps the instructions densely-packed in memory and the dispatching code fairly densely packed in memory too.
With a tree-walker, you are dereferencing pointers, skipping around in memory, and blowing the cache frequently. If you're using the Visitor or Interpreter pattern, you have the overhead of looking up the vtable, finding the method pointer, and invoking it. There's the overhead of the function call itself too -- saving and restoring registers, etc. It all adds up quickly.