YouTube CPU Tamer by AnimationFrame

𝖢𝖸 𝖥𝗎𝗇𝗀
2021-08-29T09:29:09Z

Reduce Browser's Energy Impact for playing YouTube Video

English | 日本語 | 中文

This script only works with browsers supporting Graphics Acceleration.

Please make sure you install the script from greasyfork.org, not fake sites.

Minimum Browser Versions:

Inspired by kona's YouTube CPU Tamer

Breaking Change in 2024.02.25
The script is rewritten in 2024.02.25.

1. 2021.08.29 ↝ YouTube CPU Tamer by AnimationFrame ⇶ General Page (Timer Mechanism)

2. 2023.06.17 ↝ YouTube Live Chat Tamer

3. 2023.07.25 ↝ YouTube Super Fast Chat ⇶ Live Chat Page (Data Manipulation, DOM Manipulation, Rendering)

4. 2023.08.27 ↝ YouTube JS Engine Tamer ⇶ YouTube Page (JS Engine Optimization & Fix)

Compatible with Tampermonkey / Violentmonkey / FireMonkey
Description
This userscript reduces CPU and energy consumption on YouTube pages (main page, embedded videos, live chats, and YouTube Music) by optimizing JavaScript timer management. It leverages requestAnimationFrame for efficient task scheduling, aligning executions with the browser's rendering cycle.

- Faster performance: Reduces unnecessary task execution.
- More stable playback: Prioritizes video-related tasks.
- Lower battery usage: Minimizes CPU load, especially on laptops and mobile devices.

Note 1: Overrides native setTimeout, setInterval, clearTimeout, and clearInterval functions.
Note 2: Requires GPU acceleration; uses requestAnimationFrame for efficiency.
Note 3: Adjusts task frequency in background tabs to save energy.

Script Description
"YouTube CPU Tamer by AnimationFrame" is a userscript crafted to lower your browser's energy footprint while streaming YouTube videos. Here's how it works, what it does, and how to use it:
What does it do?
The script optimizes JavaScript timers (setTimeout and setInterval) that YouTube heavily relies on, reducing CPU usage and power consumption for a smoother, more efficient experience.
How does it work?
Upon activation, it performs these key operations:

1. Custom Timer Overrides: Replaces native setTimeout and setInterval with versions that use requestAnimationFrame, syncing tasks with the browser's rendering cycle to cut down on redundant processing.
2. Optimized Task Scheduling: Employs a continuous requestAnimationFrame loop to manage pending tasks, enhancing efficiency over traditional timers, especially for animations and UI updates.
3. Interval Management: Balances the execution frequency of recurring tasks to maintain functionality without overloading the CPU.
4. Background Optimization: Reduces task execution rates in inactive tabs, leveraging browser throttling to conserve energy.
5. Error Prevention: Includes safeguards against duplicate calls and ensures compatibility with YouTube's dynamic loading.
How to Install and Use:
1. Install a userscript manager (e.g., Tampermonkey, Violentmonkey, or FireMonkey).
2. Add the script via your manager.
3. It runs automatically on YouTube pages—no further action required.

Effectiveness may vary based on device specs, YouTube page type, and other extensions. Keep your browser and manager updated for best results.

Suggested Related Scripts
Full List here

Tabview Youtube Totara

Youtube Live Borderless & YouTube Video Resize Fix

YouTube Chat Bubbles & YouTube Chat Tints

YouTube CPU Tamer by AnimationFrame; YouTube Super Fast Chat; YouTube JS Engine Tamer

YouTube: Audio Only; Disable YouTube AutoPause (Desktop)

YouTube Music: Audio Only; Disable YouTube AutoPause (Music)

YouTube: Quality Auto Max; AutoPlay Next More Than 3 seconds; Exit Fullscreen on Video End

Restore YouTube Username

Unhold YouTube Resource Locks

Reset YouTube Settings

Force YouTube AV1 (Chrome/Firefox/Opera)

If you are looking for the way to watch YouTube with least CPU resources in your old machine, please use YouTube Minimal on PC and YouTube Minimal Fixs

Further Reading - Timer Throttling
What Happens to setTimeout() / setInterval() Timers Running on Inactive Browser Tabs ?

Heavy throttling of chained JS timers beginning in Chrome 88
Sample Testing Links

Live Chat (星街すいせい)

Also see...

CY Fung - Tabview Youtube Totara

CY Fung - HTML Video Player Enhance

CY Fung - Youtube Subtitle Caption Stylish

CY Fung - Youtube MiniView

Cptmathix - YouTube Play Next Queue

Cptmathix - Youtube - Search While Watching Video