Skip to content

perf(FragmentsModels): use Set lookup for itemIds filter in getItemsByAttribute#246

Merged
agviegas merged 1 commit into
ThatOpen:mainfrom
rihokirss:perf/itemids-set-lookup
Jul 16, 2026
Merged

perf(FragmentsModels): use Set lookup for itemIds filter in getItemsByAttribute#246
agviegas merged 1 commit into
ThatOpen:mainfrom
rihokirss:perf/itemids-set-lookup

Conversation

@rihokirss

Copy link
Copy Markdown
Contributor

Problem

getItemsByAttribute checks candidate membership with Array.includes inside its loop over all items:

if (itemIds?.length && !itemIds.includes(localId)) continue;

Any getItemsByQuery that passes a candidate list (e.g. a categories pre-filter resolving to many items) becomes O(n × m). On a real-world 43 MB model, a pset query (categories: [/^IFCPROPERTYSET$/i] + attribute + relation) has 121k candidates, and a single query takes ~5 minutes.

Fix

Build a Set from itemIds once before the loop and use Set.has for the membership check. The function already builds new Set(itemIds) for missing-item tracking, so this reuses the same idea.

Results (real IFC-derived fragments model, 43 MB, 121k property sets)

Before After
Single pset getItemsByQuery ~315 s ~1.1 s

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

Complements #245 (memoized localId index lookups) — the two together take bulk property queries on this model from tens of minutes to ~1 s.

…yAttribute

getItemsByAttribute checked candidate membership with Array.includes
inside the loop over all items, making every getItemsByQuery with a
category (or other) pre-filter O(n × m). On a real 43 MB model with
121k IFCPROPERTYSET candidates a single pset query took ~5 minutes;
with a Set lookup the same query returns identical results in ~1.1 s
(measured on real IFC-derived fragments data).

The function already builds a Set of itemIds for missing-item tracking,
so this just reuses the same idea for the membership check.
rihokirss added a commit to rihokirss/engine_fragment that referenced this pull request Jul 13, 2026
…ibute

Source: fix/space-boundary-null-check (8f3941e)
- getItemsByQuery with a category pre-filter was O(n x m)
  (Array.includes per item); 43MB model pset query: ~315 s -> ~1.1 s
- upstream PR: ThatOpen#246
@agviegas
agviegas merged commit ce1f686 into ThatOpen:main Jul 16, 2026
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