Repository navigation
Conversation
Owner
|
Landed in 0d691dc, and this is a great one. Thank you! I benchmarked it against main with alternating runs and got 1.5-2x on fuzzy search and up to 2.4x on token search, with the non-Bitap paths unchanged. A differential run of a few thousand random searches across option combinations came back identical to main. One change on top in 830626a. The shared arrays grew to fit the longest text ever searched and never shrank, so a single 5M-character document kept 67 MB alive for the life of the process. Reuse is now capped at 64k entries and longer texts get one-off arrays, which keeps the speedup for normal text and caps retained memory at about 512 KB. |
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.
Summary
Up to ~1.9x faster fuzzy search.
search()allocated a new array for every error level of every text, and read each character as a one-character string to look it up in the alphabet. This PR reuses two typed arrays and looks characters up by char code.Benchmarks
20k docs (faker), keys
title,author,tags, default options. Median of 7 runs, Node 25:chairgrniteErgonomic Steelfrsh tunaxqLonger queries gain more, because they run more error levels per text.
What changed
search()reuses two module-levelInt32Arrays and swaps them between error levels. It grows them when a longer text comes in, and zero-fills the part each level reads, so unwritten slots still read as 0 likeundefineddid.createPatternAlphabet()keys the alphabet bycharCodeAt, andsearch()reads text withtext.charCodeAt(i).Correctness
All 543 tests pass and lint is clean. Results are the same as main (
JSON.stringifyof the output) for 66 option and query combinations:includeMatches,minMatchCharLength,ignoreLocation,findAllMatches,isCaseSensitive,ignoreDiacritics, weighted keys, patterns over 32 characters, and CJK and accented text. Newtest/bitap-buffers.test.jscovers reusing the arrays between long and short texts, texts longer than the first buffer, and non-Latin characters.