Skip to content

perf(FragmentsModels): memoize localId index lookups in properties controller#245

Merged
agviegas merged 1 commit into
ThatOpen:mainfrom
rihokirss:perf/localid-index-memoization
Jul 15, 2026
Merged

perf(FragmentsModels): memoize localId index lookups in properties controller#245
agviegas merged 1 commit into
ThatOpen:mainfrom
rihokirss:perf/localid-index-memoization

Conversation

@rihokirss

Copy link
Copy Markdown
Contributor

Problem

getItemAttributes and getItemRelations in VirtualPropertiesController resolve the flatbuffer array index with a linear indexOf scan on every call:

const index = this._model.localIdsArray()?.indexOf(localId);

Any bulk read (e.g. getItemsData over all property sets, property panels, relation traversals) becomes O(n²). On a real-world 43 MB model with 121k IFCPROPERTYSET items, reading pset names + property values via getItemsData took 18+ minutes of CPU.

Fix

Memoize a localId → index Map for both localIdsArray and relationsItemsArray. The flatbuffer accessors return a fresh TypedArray view on every call, so the memo is keyed by the underlying buffer identity + length instead of array identity, and rebuilds automatically if the model buffer changes (e.g. after edits regenerate the buffer). Items created via edit requests are absent from the map, so lookups fall through to the existing index === -1 code path unchanged.

Results (real IFC-derived fragments models)

Operation Before After
getItemsData over 34k psets + 394k properties (17 MB model) 41 s 2.2 s
getItemsData over 121k psets (43 MB model) 18+ min ~13 s

Query results verified identical before/after on real project filters (element sets compared pairwise).

No API changes; single file touched.

…ntroller

getItemAttributes and getItemRelations resolved the flatbuffer array index
with a linear indexOf scan on every call, making bulk property reads
(e.g. getItemsData over all property sets) O(n²). On a 43MB model with
121k property sets this took 18+ minutes; with a memoized localId -> index
Map it takes seconds.

The flatbuffer accessors return a fresh TypedArray view on every call, so
the memo is keyed by the underlying buffer identity and length instead of
array identity, and rebuilds automatically if the model buffer changes.
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.

2 participants