Skip to content

perf(str): use string.find in str.oneline - #2245

Merged
hrsh7th merged 1 commit into
hrsh7th:mainfrom
hood:perf/str-oneline
Nov 5, 2026
Merged

hrsh7th merged 1 commit into
hrsh7th:mainfrom
hood:perf/str-oneline

Conversation

@hood

@hood hood commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Closes #2239

Summary

str.oneline now uses string.find(text, '\n', 1, true) instead of a Lua loop over every byte. It also removes the now-unused NR_BYTE constant.

Data

Time to build entries over 10 keystrokes. CPU time, best of 20. Benchmark in #2236.

Scenario Before After
6k items, isIncomplete 153.7 ms 143.7 ms (-7%)
20k items, isIncomplete 545.1 ms 514.9 ms (-6%)

Gives the same output as before for empty strings, a leading/trailing/repeated \n, and \r\n.

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 0cff98b into hrsh7th:main Nov 5, 2026
njhoffman pushed a commit to njhoffman/nvim-cmp that referenced this pull request Nov 6, 2026
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: str.oneline scans strings byte by byte in Lua

2 participants