Skip to content

Conversation

@GaoFuhong
Copy link
Collaborator

Description

主要改动:

  1. 【主要】新增 pendingJobs,去重合并同一任务,对同一 id 的重复任务不再追加多条队列项,使用 Map 更新已存在任务的 cbpriority
  2. flushJobs() 中在 requestIdleCallbacktimeRemaining() 时优先使用剩余时间作为预算,否则才用帧预算 frameInterval,把原来的 frameInterval 33 改为 16,更接近 60 fps。
  3. scheduleJob() 中增加 requestAnimationFrame,处理 Safari 等环境。

试验对比:

  1. 更新节点属性:
image
不去重(Before) 去重(After)
不去重 去重
入队多少就执行多少 同一节点在一个 tick 内做 3 次属性更新,会合并两次,执行数远小于入队数
  1. 平移:优先级为 JOB_PRIORITY.PRIOR,直接执行,不受影响
Before After
image image

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Enhancement (changes that improvement of current feature or performance)
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Test Case (changes that add missing tests or correct existing tests)
  • Code style optimization (changes that do not affect the meaning of the code)
  • Docs (changes that only update documentation)
  • Chore (changes that don't modify src or test files)

Self Check before Merge

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @GaoFuhong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the job queuing mechanism to improve performance and efficiency. By introducing task deduplication, the system avoids redundant processing of identical jobs within a single tick. Furthermore, the scheduling logic has been refined to leverage browser idle time more effectively and to ensure smoother execution across different environments, aiming for a more consistent 60 frames per second experience.

Highlights

  • Task Deduplication: Implemented a 'pendingJobs' Map to prevent duplicate tasks with the same ID from being added to the queue. Instead, existing tasks' callbacks and priorities are updated, ensuring only the latest state of a task is processed.
  • Optimized Job Flushing: The 'flushJobs' method now intelligently uses 'requestIdleCallback''s 'timeRemaining()' as a budget, falling back to a reduced 'frameInterval' (16ms from 33ms) for more responsive processing and a target closer to 60 frames per second.
  • Enhanced Scheduling Compatibility: 'scheduleJob' now includes 'requestAnimationFrame' as an intermediate scheduling mechanism between 'requestIdleCallback' and 'setTimeout', providing better compatibility and performance across various browser environments, including Safari.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

你好,感谢你对 JobQueue 的优化。这次重构通过引入 pendingJobs 来合并重复任务,显著减少了不必要的队列操作,从性能测试图来看效果很明显。在 flushJobs 中动态调整执行预算,以及在 scheduleJob 中增加 requestAnimationFrame 作为备用方案,都是非常棒的改进,提升了渲染的流畅性和环境兼容性。

代码整体质量很高,我只发现了一些小问题,主要是在 cancelScheduleJob 中有一个潜在的逻辑 bug,以及一处可以简化的代码。具体细节请看我的评论。

做得很好!

@hustcc
Copy link
Member

hustcc commented Oct 30, 2025

这类代码人工加单测,每个 pr 都注意加单测。之前批量 ai 加单测,其实单测质量、有效性不高的。

@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 97.01493% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.89%. Comparing base (c1a3562) to head (33f13d7).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/renderer/queueJob.ts 97.01% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4859      +/-   ##
==========================================
- Coverage   81.94%   81.89%   -0.05%     
==========================================
  Files         327      329       +2     
  Lines       38019    38044      +25     
  Branches     7637     7625      -12     
==========================================
+ Hits        31153    31156       +3     
- Misses       6841     6863      +22     
  Partials       25       25              
Flag Coverage Δ
x6 81.89% <97.01%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/renderer/queueJob.ts 98.11% <97.01%> (-0.25%) ⬇️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GaoFuhong GaoFuhong merged commit c96db56 into master Oct 31, 2025
2 checks passed
@GaoFuhong GaoFuhong deleted the refactor-queue-job branch October 31, 2025 03:49
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.

5 participants