MeshRelation: precompute exclusion lookups outside the hot loop#69
Merged
Merged
Conversation
isExcluded was called O(M*R) times from the nearest-neighbor loop. Each
call rebuilt active-pattern closures, repeatedly uppercased the same
strings, allocated "EXCLUDE." + refA / "INCLUDE." + refA, and even hit
Logging.getLogOnceFn (dictionary lookup + string concat) on every
iteration of every mod annotation.
Replace it with a one-time precompute that produces:
- refUncondExcl : bool[] (any annotation == "EXCLUDE")
- refGroups : HashSet<string>[] (uppercased ref groups)
- modExcludeTokens / modIncludeTokens : string[][]
(the X parts of Exclude.X /
Include.X, uppercased)
The returned filter is now: O(|exclude tokens| + |include tokens|) per
(modIdx, refIdx) pair, with HashSet.Contains lookups, no allocations,
and no logging in the hot path. Diagnostic logOnce calls are fired once
at precompute time per distinct token rather than per inner-loop hit.
Behavior is preserved:
- ref vert with "EXCLUDE" annotation -> excluded
- mod "Exclude.X" + ref has group "X" -> excluded
- mod "Include.X" + ref missing group "X" -> excluded
- empty AVG arrays (either side) -> filter is a no-op, matching the
previous early-out
- out-of-range indices return false, matching the prior bounds checks
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.
isExcluded was called O(M*R) times from the nearest-neighbor loop. Each call rebuilt active-pattern closures, repeatedly uppercased the same strings, allocated "EXCLUDE." + refA / "INCLUDE." + refA, and even hit Logging.getLogOnceFn (dictionary lookup + string concat) on every iteration of every mod annotation.
Replace it with a one-time precompute that produces:
(the X parts of Exclude.X /
Include.X, uppercased)
The returned filter is now: O(|exclude tokens| + |include tokens|) per (modIdx, refIdx) pair, with HashSet.Contains lookups, no allocations, and no logging in the hot path. Diagnostic logOnce calls are fired once at precompute time per distinct token rather than per inner-loop hit.
Behavior is preserved: