Skip to content

perf(FragmentsModels): index category lookups in getItemsOfCategories - #276

Open
rihokirss wants to merge 1 commit into
ThatOpen:mainfrom
rihokirss:perf/category-index
Open

perf(FragmentsModels): index category lookups in getItemsOfCategories#276
rihokirss wants to merge 1 commit into
ThatOpen:mainfrom
rihokirss:perf/category-index

Conversation

@rihokirss

Copy link
Copy Markdown
Contributor

Closes #248.

getItemsOfCategories tested every regex against every item's category on every call (O(items × regexes)). This adds a lazily built category → localIds index over the immutable flatbuffer data, so each regex is tested once per distinct category name.

Following the review notes in the issue:

  • Lazy: built on first use, not in the constructor, and straight from the flatbuffer (categories(i) / localIds(i)), independent of _items.
  • Keyed by the underlying buffer identity and categoriesLength(), so it rebuilds if the model buffer is regenerated.
  • Covers the stored data only; the pending edit-request overlay (created/updated/deleted items) is still applied on top exactly as before.

Results are byte-identical to the previous implementation (same key order, same id order).

Measurements

43 MB model, ~1.5M items, 23 categories: /^IFCPROPERTYSET$/i 770 ms → 10 ms on repeat, /TYPE$/i 755 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.

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.
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.

getItemsOfCategories is O(items × regexes) per call — category index makes repeated calls faster

1 participant