You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Technical Documentation: Memory Usage in Canvas operations (sp-color-area)
Overview
The ColorArea component is a memory-intensive component due to its canvas-based operations and color manipulation functionality. This document explains why certain memory usage is expected and cannot be fully eliminated, as well as why the current memory testing approach is appropriate.
Memory Usage Analysis
Expected Memory Footprint
The ColorArea component has a baseline memory footprint of approximately 12KB, which is primarily composed of:
Gradient Patterns: These define the color space and are stored in memory.
Color Calculations: Every color change involves calculations across multiple color models.
Event Processing: Pointer events update color selection dynamically.
Resize Handling: The ResizeObserver ensures proper layout adjustments.
Memory Testing Approach used in SWC
Our testForMemoryLeaks function focuses on detecting memory leaks, not enforcing a strict memory limit. It:
Creates and destroys the component 50 times.
Measures heap usage before and after.
Ensures memory usage stays stable.
Why Canvas Operations like sp-color-area Are Excluded from Memory Testing?
Canvas-based components naturally use more memory. 12KB is reasonable given that ColorArea performs:
Visual rendering (gradients, colors)
User interactions (event handling, state updates)
Complex calculations (color conversions)
For context:
A simple button: 1-2KB
A form component: 5-10KB
A data grid with filtering: 20-50KB
Is 12KB a Problem?
12KB of memory usage is not necessarily a problem, especially for a component that:
Performs complex visual operations
Handles user interactions
Manages state and color transformations
For comparison:
A simple HTML button might use 1-2KB
A complex form component might use 5-10KB
A data grid with sorting and filtering might use 20-50KB
Conclusion
The ColorArea component’s memory footprint is expected due to its complexity. While it cannot be fully reduced, our memory testing approach effectively prevents leaks by ensuring stable memory usage over time. Proper cleanup in disconnectedCallback guarantees that resources are released, maintaining performance and reliability.
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.
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
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.
Technical Documentation: Memory Usage in Canvas operations (sp-color-area)
Overview
The
ColorAreacomponent is a memory-intensive component due to its canvas-based operations and color manipulation functionality. This document explains why certain memory usage is expected and cannot be fully eliminated, as well as why the current memory testing approach is appropriate.Memory Usage Analysis
Expected Memory Footprint
The
ColorAreacomponent has a baseline memory footprint of approximately 12KB, which is primarily composed of:Component Structure: ~2-3KB
ColorController,LanguageResolutionController)Canvas Operations: ~4-5KB
Event Handling: ~2-3KB
DOM References: ~1-2KB
Why Canvas Operations Are Memory-Intensive?
Canvas-based rendering requires additional memory because:
ResizeObserverensures proper layout adjustments.Memory Testing Approach used in SWC
Our
testForMemoryLeaksfunction focuses on detecting memory leaks, not enforcing a strict memory limit. It:Why Canvas Operations like
sp-color-areaAre Excluded from Memory Testing?Canvas-based components naturally use more memory. 12KB is reasonable given that
ColorAreaperforms:For context:
Is 12KB a Problem?
12KB of memory usage is not necessarily a problem, especially for a component that:
For comparison:
Conclusion
The
ColorAreacomponent’s memory footprint is expected due to its complexity. While it cannot be fully reduced, our memory testing approach effectively prevents leaks by ensuring stable memory usage over time. Proper cleanup indisconnectedCallbackguarantees that resources are released, maintaining performance and reliability.