YouTube CPU Tamer by AnimationFrame

减少YouTube影片所致的能源消耗

安装此脚本?
作者推荐脚本

您可能也喜欢YouTube 超快聊天

安装此脚本
作者
𝖢𝖸 𝖥𝗎𝗇𝗀
日安装量
9
总安装量
41,197
评分
62 5 0
版本
2024.05.13.0
创建于
2021-08-29
更新于
2025-02-22
大小
20.7 KB
许可证
MIT
适用于

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
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

Also see...