no-context / moo

Optimised tokenizer/lexer generator! 🐄 Uses /y for performance. Moo.
BSD 3-Clause "New" or "Revised" License
821 stars 65 forks source link

Fast case for single characters #40

Closed tjvr closed 6 years ago

tjvr commented 7 years ago

charCodeAt() is unresonably fast. This makes the JSON benchmark ~50% faster.

Note we can only do this for single characters at the top of the lexer definition. :-)

bd82 commented 7 years ago

Cool 👍

tjvr commented 6 years ago

I'm torn on this--it seems like adding a bunch of complexity just to game a particular benchmark :confused:

Is this as fast if we use [0] rather than charCodeAt(0)?

nathan commented 6 years ago

@tjvr

just to game a particular benchmark

I'm not sure it's just this benchmark. A lot of languages have single-character operators, and this speeds up lexing those a lot. A lot of languages also have multi-character operators, and we might want to think about speeding those up too—but since single characters result in the most dense token stream (and thus the highest potential for slowness), a fast case for single characters might be worth it.