Skip to content

perf(char): use lookup tables in match and is_semantic_index - #2246

Merged
hrsh7th merged 1 commit into
hrsh7th:mainfrom
hood:perf/char-lookup-tables
Nov 5, 2026
Merged

hrsh7th merged 1 commit into
hrsh7th:mainfrom
hood:perf/char-lookup-tables

Conversation

@hood

@hood hood commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Closes #2240

Summary

  • char.match now uses a 256-entry lowercase table: LOWER[a] == LOWER[b].
  • char.is_semantic_index reads both bytes with one string.byte call and checks the alpha/ALPHA/digit tables directly, without going through the helper functions.

The public char.* helpers are unchanged.

Data

CPU time, best of 20. Benchmark in #2236.

Metric Before After
matcher.match x60k 44.9 ms 27.2 ms (-39%)
get_entries, 6k items, isIncomplete 69.9 ms 62.2 ms (-11%)
get_entries, 20k items, isIncomplete 237.7 ms 208.5 ms (-12%)

Same results

Checked against the current char.lua and matcher.lua:

Check Cases Differences
char.match: all byte pairs, including nil 66,049 0
is_semantic_index: all 2-byte strings, index 0..3 262,144 0
matcher.match: random words x inputs x matching options (same score and matches) 210,000 0

Testing

All 73 specs pass, luacheck reports 0 warnings, and touched files are formatted with stylua.

@hrsh7th

hrsh7th commented Nov 5, 2026

Copy link
Copy Markdown
Owner

thank you.

@hrsh7th
hrsh7th merged commit fe29aba into hrsh7th:main Nov 5, 2026
njhoffman pushed a commit to njhoffman/nvim-cmp that referenced this pull request Nov 6, 2026
…ndex (hrsh7th#2246) (fe29aba)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: matcher char helpers cost several calls per byte

2 participants