Skip to content

Improve the polifill for setImmediate for max performance#72

Merged
arianrhodsandlot merged 2 commits intoarianrhodsandlot:mainfrom
bangnokia:main
Dec 24, 2025
Merged

Improve the polifill for setImmediate for max performance#72
arianrhodsandlot merged 2 commits intoarianrhodsandlot:mainfrom
bangnokia:main

Conversation

@bangnokia
Copy link
Contributor

@bangnokia bangnokia commented Dec 23, 2025

This PR addresses a significant performance bottleneck in the previous setImmediate polyfill implementation, which relied on setTimeout(..., 0) as a fallback. While simple, this approach introduces delays (often clamped to at least 1-4ms in browsers due to timer nesting rules), limiting high-frame-rate scenarios.

On my machine, the old implementation capped performance at ~150 FPS (roughly 3x fast-forward ratio) in fast-forward mode.

The new polyfill uses a more efficient fallback (e.g., MessageChannel where available, with graceful degradation), allowing smoother execution and higher speeds (tested up to 4x+ fast-forward).

@bangnokia bangnokia marked this pull request as ready for review December 23, 2025 22:51
Copy link
Owner

@arianrhodsandlot arianrhodsandlot left a comment

Choose a reason for hiding this comment

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

Thanks!

@arianrhodsandlot arianrhodsandlot merged commit 6dcd05e into arianrhodsandlot:main Dec 24, 2025
4 checks passed
@arianrhodsandlot arianrhodsandlot added the enhancement New feature or request label Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants