跳到正文
Skillpedia
网站与界面(前端)75k · #3007

scheduler-yield

它能做什么

这个技能找出可能冻结页面的长时间 JavaScript 循环和递归工作,并添加暂停点,让浏览器能够响应。它面向在大量处理时页面显得卡住的前端开发者。

适用场景

  • ✓你请智能体防止页面在处理大量数据时冻结的时候。
  • ✓应用中的繁重任务执行时,点击或输入感觉延迟的时候。
  • ✓你审查带有大循环或大量 DOM 更新的代码,并希望保持界面响应的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/scheduler-yield/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/scheduler-yield/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的页面处理大列表时会卡住一会儿。请帮我把这些工作拆分开,让页面保持响应吗?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会找出可能超过约 50 毫秒的循环和批量操作。它会重构这些代码,使其在各块之间使用 scheduler.yield 暂停;如果该函数不可用,则使用备用方案。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Use scheduler.yield() to keep the main thread responsive during long tasks

Any JavaScript task longer than 50 ms blocks the browser's main thread, preventing it from processing clicks, keyboard events, and rendering frames. Yielding between chunks of work keeps Interaction to Next Paint (INP) low and makes the page feel responsive even during heavy computation.

Quick Reference

  • Tasks longer than 50 ms block input and hurt Interaction to Next Paint (INP)
  • scheduler.yield() pauses execution, lets the browser handle queued input, then resumes
  • Use a MessageChannel-based polyfill where scheduler.yield() is unavailable
  • Apply to data processing loops, tree traversals, and bulk DOM mutations

Check

Identify synchronous loops, recursive traversals, or bulk operations in this code that could run for more than 50 ms and block user input.

Fix

Refactor long synchronous tasks to yield to the browser between chunks using scheduler.yield() with a MessageChannel fallback.

Explain

Explain why tasks longer than 50 ms hurt INP, how scheduler.yield() works, and when to use it versus Web Workers.

Code Review

Review event handlers, data transformation functions, and initialization routines for synchronous loops over large collections that could block input. Flag any loop where the total work could exceed 50 ms.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/scheduler-yield

常见问题

为什么 50 毫秒很重要?

这个技能说,超过 50 毫秒的任务会占用主线程,可能延迟点击和渲染。

什么时候应改用 Web Workers?

这个技能提到可以把 scheduler.yield 与 Web Workers 进行比较,后者会把工作移到主线程之外。

这对响应速度有什么影响?

这个技能说,它有助于降低 Interaction to Next Paint,使页面在繁重工作时感觉更流畅。

详情

作者的原始描述

Use when reviewing JavaScript that performs synchronous loops over large datasets, recursive tree traversals, or bulk DOM updates that may exceed 50 ms on mid-range devices.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#3007
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能