Skip to content

Fix: Add debouncing to theme updates to prevent CPU spike#3590

Merged
ImprovedTube merged 1 commit intocode-charity:masterfrom
AryaXDG:fix/theme-cpu-spike-debounce
Feb 3, 2026
Merged

Fix: Add debouncing to theme updates to prevent CPU spike#3590
ImprovedTube merged 1 commit intocode-charity:masterfrom
AryaXDG:fix/theme-cpu-spike-debounce

Conversation

@AryaXDG
Copy link
Contributor

@AryaXDG AryaXDG commented Feb 2, 2026

Summary

This PR fixes a critical performance issue where rapidly switching themes or using the color picker caused CPU usage to spike to 100% (Issue #3588).

Technical Details

The issue was caused by the extension triggering a full style recalculation and DOM repaint for every single input event. When a user rapidly clicked themes or dragged the color picker, ImprovedTube.myColors() and ImprovedTube.setTheme() were called dozens of times per second, overwhelming the browser's rendering engine.

Changes:

  • Implemented a debounce mechanism in js&css/web-accessible/core.js for the storage-changed event listener.
  • The theme update functions are now wrapped in a setTimeout (200ms).
  • This ensures that heavy CSS injections only occur once the user has stopped their interaction, rather than on every intermediate step.

Fixes

Fixes #3588

@ImprovedTube ImprovedTube merged commit c0c345f into code-charity:master Feb 3, 2026
1 check passed
@ImprovedTube
Copy link
Member

thank you! @AryaXDG

would you also like to join us as a mentor for google summer of code if we are accepted?
(guiding a student with a project of 90 to 360 hours, some payment, option to travel there)

@AryaXDG
Copy link
Contributor Author

AryaXDG commented Feb 3, 2026

Hey! @ImprovedTube
Thank you so much for this invitation!!! I would be honored to join the team as a Mentor for GSoC!

I am also looking forward to continuing my own active contributions to the project alongside guiding the students 😄

Here is my email for the official invite and next steps if we get accepted: aryadasgupta2004@gmail.com

Let's do this!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 CPU spikes to 100% if changing themes too fast

2 participants