Files
ladybird/Tests/LibWeb/Text/input/html/timer-nesting-level-clamping.html
Tim Ledbetter 7577fd2a57 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.
2026-02-11 16:32:20 +00:00

24 lines
752 B
HTML

<!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>