perf(FragmentsModels): index category lookups in getItemsOfCategories - #276
Open
rihokirss wants to merge 1 commit into
Open
perf(FragmentsModels): index category lookups in getItemsOfCategories#276rihokirss wants to merge 1 commit into
rihokirss wants to merge 1 commit into
Conversation
getItemsOfCategories tested every regex against every item's category on every call — O(items x regexes) per call, ~750 ms on a 43 MB model with ~1.5M items. The flatbuffer category data is immutable, so a lazily built category -> localIds Map (keyed by the underlying buffer identity) lets each call test regexes once per distinct category name instead. Measured on real IFC-derived fragments data (43 MB, 23 categories): repeated calls ~750-1100 ms -> 0.3-10 ms, first call equal or faster; results byte-identical (including key order and id order). Edit-request handling (created/updated/deleted items) is unchanged.
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.
Closes #248.
getItemsOfCategoriestested every regex against every item's category on every call (O(items × regexes)). This adds a lazily builtcategory → localIdsindex over the immutable flatbuffer data, so each regex is tested once per distinct category name.Following the review notes in the issue:
categories(i)/localIds(i)), independent of_items.categoriesLength(), so it rebuilds if the model buffer is regenerated.Results are byte-identical to the previous implementation (same key order, same id order).
Measurements
43 MB model, ~1.5M items, 23 categories:
/^IFCPROPERTYSET$/i770 ms → 10 ms on repeat,/TYPE$/i755 ms → 1 ms,/^IFC/i(all categories) 1132 ms → 123 ms.Headless Chromium, 40k-item model, three regexes: first call 38.9 → 19.2 ms, repeat call 18.1 → 0.3 ms, identical results.