Files
AFFiNE/packages/frontend/client
DarkSky 0223894d82 perf(client): score search fields before building hits
Search now scores documents without allocations and builds highlights
only for the documents it returns.

- `PreparedQuery` lowercases each field into a reusable `QueryScratch`
  buffer. ASCII text uses ASCII lowercase and skips UTF-16 tables.
  Other text uses `str::to_lowercase()`, and maps lowercase bytes to
  source UTF-16 ranges only when the field contains the query.

- `score_with_scratch` returns the field score without highlight spans.
  `match_utf16_with_scratch` returns the same result as `match_utf16`.

- With a limit, `WeightedSearchEngine::search_refs` keeps the best
  documents in a bounded heap. Then it builds hits for those documents
  only. Ties resolve as in a stable full sort.

- With no limit, search matches each document once and sorts the hits.

On 4,096 documents with 2,048-byte bodies and a limit of 20, a query
that matches every document allocates 0.04 MB instead of 188 MB.
2026-12-04 09:43:21 +09:00
..