admin管理员组文章数量:1424445
I am testing out a test case a friend of mine noticed. He was using window.innerheight in a loop, and there was a very significant drop in the fps.
Here is the link to the jsperf I created to test it
The only explanation I can e up with is that this is a getter, and calculates the actual height, on every call. Is that right? Any documentation where I can verify this?
I am testing out a test case a friend of mine noticed. He was using window.innerheight in a loop, and there was a very significant drop in the fps.
Here is the link to the jsperf I created to test it http://jsperf./innerheight
The only explanation I can e up with is that this is a getter, and calculates the actual height, on every call. Is that right? Any documentation where I can verify this?
Share Improve this question asked Jul 14, 2012 at 19:51 AmitAmit 4,0007 gold badges47 silver badges84 bronze badges 1- 1 window.innerheight is a getter, then have a function behind the .innerheight, when you save on a variable, you just save the result – GTSouza Commented Jul 14, 2012 at 19:54
2 Answers
Reset to default 7This question was posted a few years back, but just in case someone else finds their way here experiencing similar results.
From this blog:
The problem is WebKit likes to recalculate the layout of the dom pretty much every single time you use something similar to getBoundingClientRect. (Even getting the window.innerHeight/innerWidth will force a recalculation) ... All calls to get any calculated dimension from the DOM should be cached or avoided.
Caching window dimensions once on initialization and on each resize improved performance for me significantly.
In your first loop (innerheight), you are accessing an objects property and assigning it to h
. In the second loop (cached), you just have h
. Of course the cached one will be faster.
本文标签: javascriptwhy is the performance of this windowinnerheight so badStack Overflow
版权声明:本文标题:javascript - why is the performance of this window.innerheight so bad? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745416330a2657700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论