Skip to content

perf: cache removeDiacritics results in getMatches to avoid redundant… - #545

Open
yoshi-taka wants to merge 4 commits into
scambier:developfrom
yoshi-taka:cache-diacritics
Open

perf: cache removeDiacritics results in getMatches to avoid redundant…#545
yoshi-taka wants to merge 4 commits into
scambier:developfrom
yoshi-taka:cache-diacritics

Conversation

@yoshi-taka

Copy link
Copy Markdown

… computation

getMatches() is called for each search result (up to 50) and recomputes removeDiacritics() on the full document text every time when ignoreDiacritics is enabled.

Add a small bounded cache for normalized text to avoid repeated full-string normalization during repeated search-result rendering passes.

The cache:

  • is keyed by both the input text and the ignoreArabicDiacritics setting flag, so changing the setting does not reuse stale normalized text
  • is capped at 100 entries to limit memory growth
  • uses FIFO eviction to keep the implementation simple and memory usage bounded

This trades a small amount of bounded memory for less repeated normalization work in the search rendering path.

… computation

getMatches() is called for each search result (up to 50) and recomputes
removeDiacritics() on the full document text every time when
ignoreDiacritics is enabled.

Cache results with a bounded Map (max 100 entries) using a key that
includes the ignoreArabicDiacritics setting flag to avoid stale entries
when the setting changes. FIFO eviction keeps memory bounded.
@scambier
scambier changed the base branch from master to develop August 23, 2026 12:06
@scambier

Copy link
Copy Markdown
Owner

Hello and thanks for your PR :) Could you please just solve the conflict, so I can merge it? Thank you.

apple-ouyang and others added 3 commits August 23, 2026 14:25
Exact-term matching only evaluates the candidate results after they have been limited.

Normalize the original document content at that point instead of keeping a normalized full-text copy in every cached document.
Resolve conflict in text-processing.ts by keeping both highlightRegexCache and diacriticsCache
@yoshi-taka

Copy link
Copy Markdown
Author

I've resolved the conflicts. Sorry for the delay!

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.

3 participants