perf(FragmentsModels): use Set lookup for itemIds filter in getItemsByAttribute#246
Merged
Merged
Conversation
…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
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.
Problem
getItemsByAttributechecks candidate membership withArray.includesinside its loop over all items:Any
getItemsByQuerythat passes a candidate list (e.g. acategoriespre-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
SetfromitemIdsonce before the loop and useSet.hasfor the membership check. The function already buildsnew Set(itemIds)for missing-item tracking, so this reuses the same idea.Results (real IFC-derived fragments model, 43 MB, 121k property sets)
getItemsByQueryQuery 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.