fix(labelmap): use content-based comparison for segmentsHidden Set#2675
Open
pedrokohler wants to merge 1 commit into
Open
fix(labelmap): use content-based comparison for segmentsHidden Set#2675pedrokohler wants to merge 1 commit into
pedrokohler wants to merge 1 commit into
Conversation
Contributor
Author
|
@sedghi this is a performance optimization, it reduces allocation churn / CPU overhead during scrolling. |
Member
|
Thanks, i let QA test it |
Contributor
Author
|
@sedghi it's been almost 2 months since QA was asked to review. Could we merge? |
Member
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.
Context
_needsTransferFunctionUpdate()inlabelmapDisplay.tscomparesoldSegmentsHidden !== segmentsHiddenusing reference equality. BecausesegmentsHiddenis a newSetinstance on every render call, this comparisonalways returns
true— even when the contents are identical. This forcesforceOpacityUpdate = trueunconditionally, triggering unnecessary.slice()andnew Set()allocations on every render cycle for every segmentation.With 13 segmentations across ~180 render calls per scroll, this produces hundreds
of redundant transfer-function updates per interaction.
Changes & Results
Replace the reference comparison with a content-based comparison:
sizeequality first (fast path).[...segmentsHidden].some(idx => !oldSegmentsHidden.has(idx)).Before: transfer function updated on every render (~180 times per scroll).
After: transfer function updated only when segments are actually hidden/shown (~15 times total in a typical session).
Testing
_needsTransferFunctionUpdate—forceOpacityUpdateshould be
falsewhen no visibility changes occurred.Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Made with Cursor