mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 12:07:14 +02:00
LibWeb: Implement timer nesting level throttling
This clamps the interval of repeating timers to 4ms after they have run 5 times. This prevents CPU spinning for `setInterval()` calls with low timeouts.
This commit is contained in:
committed by
Tim Ledbetter
parent
24055b60ef
commit
7577fd2a57
Notes:
github-actions[bot]
2026-02-11 16:34:54 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/7577fd2a57b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7734 Reviewed-by: https://github.com/rcorsi ✅
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(done => {
|
||||
// With 4ms clamping after nesting level 5, running for 100ms should yield
|
||||
// roughly 5-6 unclamped calls plus approximately 25 clamped calls.
|
||||
// Without clamping, we'd get thousands of calls.
|
||||
// We test that the count is bounded, proving clamping is working.
|
||||
const testDurationMilliseconds = 100;
|
||||
let callCount = 0;
|
||||
|
||||
const id = setInterval(() => {
|
||||
callCount++;
|
||||
}, 0);
|
||||
|
||||
setTimeout(() => {
|
||||
clearInterval(id);
|
||||
|
||||
println(`Callback count bounded (< 100 in 100ms): ${callCount < 100}`);
|
||||
done();
|
||||
}, testDurationMilliseconds);
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user