Closed osa1 closed 3 years ago
I implemented this in state_functions
but cargo bench
reports 5% regression in the Lua benchmark, and even worse in a micro benchmark.
I implemented this in state_functions but cargo bench reports 5% regression in the Lua benchmark, and even worse in a micro benchmark.
This is because the current code is compiled to a jump table. Closing.
It's not uncommon for a lexer state to be compiled to dozens of states. Currently we generate code like this:
For N states this means N-1 comparisons in the worst case to the take last branch.
Instead we should compile each state to a function, then put them all in an array:
Then just do
STATES[self.state](...);
.