League-of-Foundry-Developers / compendium-browser

A module to easily browse and filter spells as well as npcs loaded from compendie
9 stars 18 forks source link

[Feature] NPC Performance #33

Closed kyleady closed 2 years ago

kyleady commented 2 years ago

This feature replaces .getDocuments() with .getIndex() to increase NPC filter performance. The method .getIndex() allows us to only request information necessary for filtering, reducing the memory cost. Further, it only needs to be constructed when new information is required for filtering, reducing the filtering times when no new information is required, such as trying out different spellings when querying NPCs by name.

Example

NPCs: Four compendiums of 2164, 319, 394, and 487 NPCs. Query: Name contains "Vampir" Result: 24 NPCs. All compendiums had to be filtered.

Old Performance: loadAndFilterNpcs: 22951.043212890625 ms New Performance: loadAndFilterNpcs: 444.22802734375 ms Comparison: 98% reduction in query time.

Test Versions

spetzel2020 commented 2 years ago

Hey, I don't have any way to contact you except through these comments; I'm @spetzel#0103 on Discord. Regardless, I've merged this PR and also fixed some bugs in 0.7.2. I had to allow for some edge cases not handled in your PR (if you include Character compendia in the search universe) but I think I have that sorted.

It would be great if you had time to try it out: https://github.com/League-of-Foundry-Developers/compendium-browser/releases/latest/download/module.json