Skip to content

Revert "Run requestIdleCallback polyfill after paint in 5ms slices of a 10ms per-frame budget" - #131

Merged
mattcosta7 merged 1 commit into
mainfrom
mattcosta7/revert-ric-scheduler
Nov 4, 2026
Merged

mattcosta7 merged 1 commit into
mainfrom
mattcosta7/revert-ric-scheduler

Conversation

@mattcosta7

Copy link
Copy Markdown
Member

Reverts #129. The source and tests go back exactly to their state before that merge (an empty diff against b4f19bd^1).

Why

#129 has no measurable benefit on real github.com pages, and it adds costs.

Benefit, measured. I ran logged-out React pages in Playwright WebKit 26.5: code view, an issues list and a repo home. Each run was about 20 s and included 45 inputs; figures are medians of 3 runs. These pages schedule 16 to 25 idle callbacks, with 4 to 8 ms of idle work in total and no single callback over 1 ms. At most 2 callbacks per run landed between an input and the next paint. Input-to-next-paint p90 was the same under the old polyfill and the new scheduler: 17/17 ms, 24/24 ms and 16/18 ms. The large gains appear only in synthetic workloads that keep the idle queue full.

Costs, measured in the same WebKit setup:

  • CPU spin. A cheap self-rescheduling callback, such as github-ui's diff loader polling an empty queue, runs about 25,000 times/s and holds about 53% of a core (Defer idle requests made during a period unless the requesting callback used its slice #130 addressed this).
  • Later idle work. The median start delay goes from 1–8 ms to 14–24 ms. Throughput-bound idle work finishes 1.6–2x later.
  • Wake-ups every frame. The page wakes every frame while any idle work is pending. A bare rAF loop costs 6.7% CPU, against 1.7% for a 125/s timer loop.

Not measured

Logged-in pages, real Safari, iOS, and slower devices. If a logged-in Safari profile shows idle callbacks regularly landing between inputs and paints, the scheduler from #129 plus #130 can be reconsidered.

Supersedes #130.

… a 10ms per-frame budget"

This reverts #129 (merge b4f19bd).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A moderate active issue remains in src/requestidlecallback.ts: nullable options are rejected and Symbol timeout values are not synchronously coerced before scheduling.

1 open issue
What changed in this PR

This pull request reverts the frame-based requestIdleCallback scheduler from #129 and restores the simpler timer-based polyfill.

Changes:

  • Restores setTimeout-based callback scheduling with a 50 ms deadline.
  • Restores direct cancellation through clearTimeout.
  • Removes scheduler-specific tests and retains basic API and deadline coverage.
File Summary Review comments
test/​requestidlecallback.js Reduces coverage to basic API and deadline behavior. No comments.
src/​requestidlecallback.ts Restores the timer-based idle callback implementation. Moderate, 4 votes: Normalize nullable options and coerce timeout values before scheduling; current handling rejects null and defers Symbol errors. Moderate, 1 vote: Establish the idle deadline when the callback starts so delayed timer tasks receive a usable budget.

Review effort: Lite (auto)

schedule()
return id
const start = Date.now()
const timeout = options.timeout || 0
@mattcosta7
mattcosta7 merged commit 7376c48 into main Nov 4, 2026
8 of 9 checks passed
@mattcosta7
mattcosta7 deleted the mattcosta7/revert-ric-scheduler branch November 4, 2026 18:58
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.

3 participants