frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Why do browsers throttle JavaScript timers?

https://nolanlawson.com/2025/08/31/why-do-browsers-throttle-javascript-timers/
29•vidyesh•3h ago

Comments

BinaryIgor•3h ago
The story of web development:

"For the time being, I’ll just do what most web devs do: choose whatever API accomplishes my goals today, and hope that browsers don’t change too much in the future."

AgentME•2h ago
It's a strategy that's worked out very well. Standards groups and browsers prioritize backwards compatibility very highly. It's hard to remember any real compatibility breakages in standardized HTML/CSS/JS features (ie. not third-party plugins like Flash).
raw_anon_1111•11m ago
Challenge accepted.

https://developer.mozilla.org/en-US/docs/Glossary/blink_elem...

BugsJustFindMe•2h ago
Because browser developers still have major incentive to care about not misusing the resources (cpu/battery) of browser users, and website developers very clearly do not.
cosmic_cheese•2h ago
This the natural consequence of a platform having high capability but low barrier to entry. Conscientious use of resources cannot be assumed and is in fact the exception rather than the rule, and so guardrails must be put in place.
estimator7292•14m ago
This is an enormous problem with software in general. IMO it's probably because software has been abstracted into the stratosphere to the point that most developers aren't at all aware of resources or even the machine it's running on. That's someone else's problem. I really hate it.
jayflux•2h ago
> Even if you’ve been doing JavaScript for a while, you might be surprised to learn that setTimeout(0) is not really setTimeout(0). Instead, it could run 4 milliseconds later:

Is this still the case? Even with this change? https://chromestatus.com/feature/4889002157015040

swsieber•2h ago
I think it's still the case. The 4ms happens if you call setTimeout nested several times. I don't know the exact limit. But it's 5-ish times where that kicks in IIRC.

Edit: Here's the MDN bit on that, I was correct:

https://developer.mozilla.org/en-US/docs/Web/API/Window/setT...

> browsers will enforce a minimum timeout of 4 milliseconds once a nested call to setTimeout has been scheduled 5 times.

And the link from there to the spec about that:

https://html.spec.whatwg.org/multipage/timers-and-user-promp...

> If nesting level is greater than 5, and timeout is less than 4, then set timeout to 4.

timhh•2h ago
I think that change is talking about the minimum timeout for the first 5 nested calls to `setTimeout(0)`.

Previously the first 5 would take 1ms, and then the rest would take 4ms. After that change the first 5 take 0ms and the rest take 4ms.

jagged-chisel•2h ago
Have I not always heard that timeout-based callbacks always run at or after the timeout, but never before?

“Do this {} at least Xms from now”, right?

d1sxeyes•1h ago
Yeah, exactly. Timeout based callbacks register a timer with the runtime, and when the timer is up, then the callback gets added to the end of the task queue (so once the timeout is up, you've got to wait for the current loop iteration to finish executing before your callback gets executed).
zamadatix•1h ago
Sure, but the nuance here is there is a (otherwise usable) range of values for which the timers are only ever "after" instead of "at or after". I.e. the lower bound is artificially increased while the upper bound remains unlimited.
jagged-chisel•32m ago
I don’t think “artificially increased” is correct. See your sibling. If the runtime waits until expiry, and only then adds the task to the end of the work queue, there’s no point at which any delayed work could happen at expiry except the work to place it on the end of (an empty) queue.

Any busy runtime (e.g. one with lots of parallel tasks, plus anything running less than optimally) will have a delay.

lelandbatey•1h ago
I always kinda figured that any "timer" in any language would technically need to work that way unless you're running a very fancy real-time system because multitasking, especially in high load scenarios, means there just may not be clock cycles available for your task at the exact millisecond you set something to execute at.

So it is with JS; I kinda figured EVERYTHING would need to be heavily throttled in a browser in order to respect the device running that browser.

nielsbot•2h ago
I remember reading that high precision timers can be used for browser fingerprinting and/or for timing attacks, but I didn't anything specifically about setTimeout()/setInterval() after searching a bit.

Also--loosening the accuracy of timers allows the system to optimize CPU power states and save battery. Again, not sure if that's related here.

Maybe someone else here can add more detail.

samsonradu•2h ago
You might be referring to the Spectre mitigation changes:

Timer precision from performance.now and other sources is reduced to 1ms (r226495)

https://webkit.org/blog/8048/what-spectre-and-meltdown-mean-...

https://trac.webkit.org/changeset/226495/webkit

jsheard•31m ago
Although you can claw that precision back by enabling cross-origin isolation for your site, at least in Firefox and Chrome, which both quantize high res timers to 100 microseconds in non-isolated contexts but only 5 microseconds in isolated contexts. I'm not sure exactly what Safari does.
timhh•2h ago
I asked about this a few years ago on SO and there is some good info: https://stackoverflow.com/q/61338780/265521

E.g. Chrome has this comment:

  // Chromium uses a minimum timer interval of 4ms. We'd like to go
  // lower; however, there are poorly coded websites out there which do
  // create CPU-spinning loops.  Using 4ms prevents the CPU from
  // spinning too busily and provides a balance between CPU spinning and
  // the smallest possible interval timer.
At the time at least the 4ms only kicks in after 5 levels of nesting, as mentioned in the article, but there was still a 1ms limit before that.

Seems like it has been removed though based on jayflux's comment.

catapart•1h ago
As someone who wrote an entire indexedDB wrapper library just to understand the "micro task" issues that are referenced in this blog post, and THEN dedicated a couple hundred words of my readme to explaining this footgun[0], I am so glad to hear about `scheduler.postTask`. That's new information to me!

Thanks for including that example!

[0] https://github.com/catapart/record-setter?tab=readme-ov-file...

j45•54m ago
Background javascript processes can really seem to add up across a lot of browser tabs firing up to stay "smart" or "current" like they're the only tab in existence in their user's life.

I'm not sure if many people struggle with browser tabs gone wild. Limiting Javascript can have varying degrees of success since it's relative to how the page/site/app is built to begin with.

UTF-8 is a brilliant design

https://iamvishnu.com/posts/utf8-is-brilliant-design
232•vishnuharidas•3h ago•103 comments

QGIS is a free, open-source, cross platform geographical information system

https://github.com/qgis/QGIS
186•rcarmo•4h ago•49 comments

Many hard LeetCode problems are easy constraint problems

https://buttondown.com/hillelwayne/archive/many-hard-leetcode-problems-are-easy-constraint/
342•mpweiher•6h ago•271 comments

EU court rules nuclear energy is clean energy

https://www.weplanet.org/post/eu-court-rules-nuclear-energy-is-clean-energy
460•mpweiher•3h ago•328 comments

The treasury is expanding the Patriot Act to attack Bitcoin self custody

https://www.tftc.io/treasury-iexpanding-patriot-act/
527•bilsbie•9h ago•405 comments

Rust: A quest for performant, reliable software [video]

https://www.youtube.com/watch?v=k_-6KI3m31M
65•raphlinus•13h ago•10 comments

3D modeling with paper

https://www.arvinpoddar.com/blog/3d-modeling-with-paper
205•joshuawootonn•7h ago•29 comments

Corporations are trying to hide job openings from US citizens

https://thehill.com/opinion/finance/5498346-corporate-america-has-been-trying-to-hide-job-opening...
137•b_mc2•5h ago•105 comments

First 'perovskite camera' can see inside the human body

https://news.northwestern.edu/stories/2025/09/first-perovskite-camera-can-see-inside-the-human-body/
13•geox•3d ago•1 comments

How FOSS Projects Handle Legal Takedown Requests

https://f-droid.org/2025/09/10/how-foss-projects-handle-legal-takedown-requests.html
63•mkesper•4h ago•5 comments

Humanely dealing with humungus crawlers

https://flak.tedunangst.com/post/humanely-dealing-with-humungus-crawlers
56•freediver•4h ago•33 comments

Qwen3-Next

https://qwen.ai/blog?id=4074cca80393150c248e508aa62983f9cb7d27cd&from=research.latest-advancement...
511•tosh•14h ago•196 comments

Vector database that can index 1B vectors in 48M

https://www.vectroid.com/blog/why-and-how-we-built-Vectroid
70•mathewpregasen•4h ago•29 comments

How to Become a Pure Mathematician (Or Statistician)

http://hbpms.blogspot.com/
49•ipnon•3d ago•44 comments

Windows-Use: an AI agent that interacts with Windows at GUI layer

https://github.com/CursorTouch/Windows-Use
87•djhu9•3d ago•16 comments

Oq: Terminal OpenAPI Spec Viewer

https://github.com/plutov/oq
74•der_gopher•6h ago•11 comments

Why do browsers throttle JavaScript timers?

https://nolanlawson.com/2025/08/31/why-do-browsers-throttle-javascript-timers/
30•vidyesh•3h ago•20 comments

Polylaminin, a drug considered capable of reversing spinal cord injury

https://www1.folha.uol.com.br/internacional/en/scienceandhealth/2025/09/groundbreaking-brazilian-...
68•_aleph2c_•2h ago•5 comments

I made a small site to share text and files for free, no ads, no registration

https://www.dum.pt/
14•MarsB•1h ago•13 comments

Building a Deep Research Agent Using MCP-Agent

https://thealliance.ai/blog/building-a-deep-research-agent-using-mcp-agent
58•saqadri•2d ago•16 comments

Advanced Scheme Techniques (2004) [pdf]

https://people.csail.mit.edu//jhbrown/scheme/continuationslides04.pdf
83•mooreds•5h ago•9 comments

OpenAI Grove

https://openai.com/index/openai-grove/
50•manveerc•5h ago•51 comments

VaultGemma: The most capable differentially private LLM

https://research.google/blog/vaultgemma-the-worlds-most-capable-differentially-private-llm/
59•meetpateltech•5h ago•12 comments

K2-think: A parameter-efficient reasoning system

https://arxiv.org/abs/2509.07604
28•mgl•4h ago•3 comments

Show HN: 47jobs – A Fiverr/Upwork for AI Agents

https://47jobs.xyz
10•the_plug•1h ago•16 comments

Doom-ada: Doom Emacs Ada language module with syntax, LSP and Alire support

https://github.com/tomekw/doom-ada
62•tomekw•6h ago•8 comments

Racintosh Plus – Rackmount Mac Plus

http://www.identity4.com/2025-racintosh-plus/
120•zdw•3d ago•26 comments

Wysiwid: What you see is what it does

https://essenceofsoftware.com/posts/wysiwid/
8•auggierose•3d ago•1 comments

I don't like curved displays

https://blog.danielh.cc/blog/curved
44•max__dev•3d ago•55 comments

Power series, power serious (1999) [pdf]

https://www.cambridge.org/core/services/aop-cambridge-core/content/view/19863F4EAACC33E1E01DE2A21...
12•signa11•2d ago•1 comments