krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.08k stars 766 forks source link

Cache field-length norm to reduce index generation time #407

Closed krisk closed 4 years ago

krisk commented 4 years ago

Description

Currently, the field-length norm is calculated for every value. Given the operation and the toFixed usage (for mantissa = 3), there are performance implications when the list size is large (> 1000 records).

We can reduce the index generation time by caching the norm value.

Describe the solution you'd like

type Norm = (
  mantissa: number
) => {
  get(value: string): number // the field length norm
  clear(): void // clears the internal cache
}