在浏览器中是否有用于滚动的特殊线程?

Is there a special thread for scrolling in a browser?

我正在为我的一个 类 写一个 JavaScript 教程,我想说明调用堆栈可以阻止其他进程,当发生这种情况时,页面交互会排队等待调用堆栈为空。

const print = function(){
 console.log( "Hello World" );
}
setTimeout(print,0);
for(let i=0 ; i < 2000000000 ; i++);
console.log();

在 运行 上面的代码之后,我让他们点击链接并调整 window 的大小,看到页面没有 re-render,但在许多网站上滚动似乎工作正常像堆栈溢出。它在 Reddit 上被屏蔽了。我已经在 Chrome 和 Firefox 上对此进行了测试,以仔细检查是否有一些优化,但它的行为相似。

我假设如果网站没有滚动相关事件的事件处理程序,则有一个用于基本滚动的特殊线程。这是因为我注意到具有粘性 headers 的网站将允许滚动,但在循环完成之前不会应用它们的粘性效果。

我在下面链接到的 Nolan Lawson 的 Microsoft 博客 post 有很多关于这个确切问题的有用信息 - 请阅读一下。这是该博客的片段 post:

As it turns out, the whole “browsers are single-threaded” story is largely true, but there are important exceptions. Scrolling, in all its various flavors, is one of those exceptions.

Over the years, browser vendors have recognized that offloading work to background threads can yield enormous improvements to smoothness and responsiveness. Scrolling, being so important to the core user experience of every browser, was quickly identified as a ripe target for such optimizations. Nowadays, every major browser engine (Blink, EdgeHTML, Gecko, WebKit) supports off-main-thread scrolling to one degree or another (with Firefox being the most recent member of the club, as of Firefox 46).

来源: Scrolling on the web: A primer