perf: fast lexer using charCodeAt comparisons and sticky regexes#4
Merged
jogibear9988 merged 4 commits intomainfrom Mar 17, 2026
Merged
perf: fast lexer using charCodeAt comparisons and sticky regexes#4jogibear9988 merged 4 commits intomainfrom
jogibear9988 merged 4 commits intomainfrom
Conversation
Inspired by the es-module-shims fast lexer approach: - Replace string character comparisons with charCodeAt() numeric comparisons - Convert all ^-anchored regexes to y-flag (sticky) regexes to avoid creating temporary substring slices on every matchRegex call - Define character code constants (Ch_*) for readability - Use charCodeAt in stringSearch utilities for hot-path comparisons - Add _advanceRange() method to avoid intermediate string allocation Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
- Move pageMarginBoxRegex to module-level pre-compiled constant - Replace _compileAtRule with explicit pre-compiled regex constants for import, charset, and namespace at-rules - Convert new RegExp() to regex literals per biome lint recommendations Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Investigate fast lexer technique for improved performance
perf: fast lexer using charCodeAt comparisons and sticky regexes
Mar 17, 2026
jogibear9988
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applies the es-module-shims fast lexer principles to the CSS parser: numeric character-code comparisons instead of string comparisons, and sticky regexes to eliminate substring allocations.
Lexer (
src/parse/lexer.ts)charCodeAt()over string indexing — all hot-path character checks (skipWhitespace,tryOpenBrace,tryCloseBrace,tryColon,skipSemicolonAndWhitespace,tryCommaAndWhitespace) now compare numeric char codes against named constants instead of creating single-char stringsmatchRegex()setsre.lastIndex = this.posand matches against the full input with theyflag, eliminating thethis.remainingsubstring slice (previously O(n) allocation per call)_advanceRange(from, to)iterates the original input by index instead of receiving an intermediate stringParser (
src/parse/index.ts)re_comment,re_media,re_keyframesName,re_pageMarginBox, etc.) compiled once asy-flag constants instead of per-parse()call_compileAtRulefactory with explicit functions using module-level regex constants for@import,@charset,@namespacecharCodeAtguards —lexer.charAt() === '@'→lexer.charCodeAt() === Ch_ATthroughoutString search utilities (
src/utils/stringSearch.ts)charCodeAt()for character dispatch in bracket/quote-aware search loopsSecurity
9 CodeQL ReDoS alerts on
@import/@charset/@namespaceregex patterns are pre-existing — the pattern is unchanged from the original_compileAtRulefactory, only moved to module scope. Theat-import-dostest case validates handling of pathological input.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
guybedford.com/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)web.archive.org/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.