oxc/crates
overlookmotel 66a7a68f9f
perf(parser): lexer byte handlers consume ASCII chars faster (#2046)
In the lexer, most `BYTE_HANDLER`s immediately consume the current char
with `lexer.consume_char()`.

Byte handlers are only called if there's a certain value (or range of
values) for the next char. This is their entire purpose. So in all cases
we know for sure that we're not at EOF, and that the next char is a
single-byte ASCII character.

The compiler, however, doesn't seem to be able to "see through" the
`BYTE_HANDLERS[byte](self)` call and understand these invariants. So it
produces very verbose ASM for `lexer.consume_char()`.

This PR replaces `lexer.consume_char()` in the byte handlers with an
unsafe `lexer.consume_ascii_char()` which skips on to next char with a
single `inc` instruction.

The difference in codegen can be seen here:
https://godbolt.org/z/1ha3cr9W5 (compare the 2 x
`core::ops::function::FnOnce::call_once` handlers).

Downside is that this does introduce a lot of unsafe blocks, but in my
opinion they're all pretty trivial to validate.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-01-16 12:31:45 +08:00
..
oxc Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
oxc_allocator Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
oxc_ast feat(ast): visit TSTypeQuery (#2021) 2024-01-14 00:38:18 +08:00
oxc_cli fix(linter): keep rules disabled if the rule is not enabled in the config (#2031) 2024-01-15 05:32:51 +00:00
oxc_codegen Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
oxc_diagnostics Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
oxc_index Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
oxc_js_regex Initialize JS Regex crates and def AST. (#1500) 2023-11-23 00:22:17 +08:00
oxc_language_server chore: remove DSL based linter plugin (#1985) 2024-01-11 04:54:39 +00:00
oxc_linter feat(linter): eslint-plugin-import no-named-as-default-member rule (#1988) 2024-01-15 11:03:04 +00:00
oxc_macros feat(linter): add a perf category (#1625) 2023-12-04 17:31:34 +08:00
oxc_minifier Commutative undefined minify (#2003) 2024-01-15 02:51:53 +00:00
oxc_parser perf(parser): lexer byte handlers consume ASCII chars faster (#2046) 2024-01-16 12:31:45 +08:00
oxc_prettier fix(prettier): Correctly print export declaration (#2014) 2024-01-13 21:26:33 +08:00
oxc_semantic feat(transformer/typescript): remove import if only have type reference (#2001) 2024-01-13 08:52:14 +00:00
oxc_span Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
oxc_syntax feat(transformer/typescript): remove import if only have type reference (#2001) 2024-01-13 08:52:14 +00:00
oxc_transformer feat(transformer/typescript): remove export specifier that import_kind is type (#2015) 2024-01-13 21:25:59 +08:00
oxc_type_synthesis refactor(rust): move to workspace lint table (#1444) 2023-11-20 14:38:10 +08:00
oxc_wasm chore(deps): bump the dependencies group with 3 updates (#2033) 2024-01-15 15:31:32 +08:00