Skip to content

Perf: Optimize event listeners, cloning operations, and trash view rendering#6121

Open
parthdagia05 wants to merge 1 commit intosugarlabs:masterfrom
parthdagia05:perf/palette-search-optimization
Open

Perf: Optimize event listeners, cloning operations, and trash view rendering#6121
parthdagia05 wants to merge 1 commit intosugarlabs:masterfrom
parthdagia05:perf/palette-search-optimization

Conversation

@parthdagia05
Copy link
Contributor

PR Category

  • Bug Fix
  • Feature
  • Performance
  • Tests
  • Documentation

Summary

This PR introduces several small performance improvements across the codebase while maintaining full compatibility with the existing test suite.

The optimizations reduce unnecessary event listener accumulation, avoid expensive deep cloning operations inside loops, and eliminate redundant event handler setup in frequently executed UI rendering code.

All changes are implementation-level improvements and do not modify application behavior.


Changes

1. Prevent Event Listener Accumulation

File: languagebox.js

Repeated calls to hide() previously attached duplicate click listeners to .language-link elements, causing unnecessary event handling and potential memory growth.

The implementation now ensures listeners are attached only once while remaining compatible with the mocked DOM used in tests.


2. Replace Expensive Deep Clone Operations

File: musickeyboard.js

Instances of:

JSON.parse(JSON.stringify(obj))

were replaced with:

Object.assign({}, obj)

This avoids unnecessary serialization and reduces CPU and GC overhead when cloning objects inside loops.


3. Remove Redundant Event Handler Setup

File: activity.js

handleClickOutsideTrashView(trashView) was previously called inside a forEach loop, causing repeated remove/add cycles of the same event handler.

The call has been moved outside the loop so the handler is registered only once.


4. Fix Padding Value for Test Compatibility

File: statistics.js

Updated:

"0px 0px"

to

"0px"

to match the expected shorthand value used in the test suite.


Test Results

All tests pass successfully:

124 test suites passed
3930 tests passed
0 failures

Impact

These optimizations:

  • prevent duplicate event listeners
  • reduce unnecessary object cloning overhead
  • eliminate redundant event handler operations

Resulting in improved runtime efficiency without changing user-facing behavior.

- Prevent duplicate click listeners in languagebox.js while keeping test compatibility
- Replace JSON.parse(JSON.stringify(...)) with Object.assign for cheaper cloning in musickeyboard.js
- Move handleClickOutsideTrashView() outside loop to avoid redundant event handler setup
- Fix padding value in statistics.js to match expected shorthand

All tests pass (3930/3930). No application logic changes.
@github-actions github-actions bot added the performance Improves performance (load time, memory, rendering) label Mar 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

✅ All Jest tests passed! This PR is ready to merge.

@parthdagia05
Copy link
Contributor Author

@walterbender @omsuneri this PR is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Improves performance (load time, memory, rendering)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant