admin管理员组文章数量:1330154
I've heard alot of people saying that accessing the arguments object is expensive. (example: Why was the arguments.callee.caller property deprecated in JavaScript?)
Btw what exactly does that statement mean at all? isn't accessing the arguments object simply a simple property lookup? what exactly is the big deal?
I've heard alot of people saying that accessing the arguments object is expensive. (example: Why was the arguments.callee.caller property deprecated in JavaScript?)
Btw what exactly does that statement mean at all? isn't accessing the arguments object simply a simple property lookup? what exactly is the big deal?
Share Improve this question edited May 23, 2017 at 12:16 CommunityBot 11 silver badge asked May 27, 2011 at 2:57 PacerierPacerier 89.8k111 gold badges384 silver badges644 bronze badges2 Answers
Reset to default 14The big deal is at least twofold:
1) Accessing the arguments object has to create an arguments object. In particular, modern JS engines don't actually create a new object for the arguments every time you call a function. They pass the arguments on the stack, or even in machine registers. As soon as you touch arguments
, though, they have to create an actual object. This is not necessarily cheap.
2) Once you touch the arguments object, various optimizations that JS engines can otherwise perform (e.g. detecting cases in which you never assign to an argument and optimizing that mon case) go out the window. Every access to the function arguments, not just ones through arguments
bees much slower because the engine has to deal with the fact that you might have messed with the arguments via arguments
.
I have also never heard a serious explanation for why accessing the arguments object is expensive. However, this site: http://www.playmycode./blog/2011/03/simple-yet-effective-javascript-optimisations/ notes that arguments is not really an array and is less efficient than accessing an array. The above linked site even suggests converting arguments to an array as an optimization.
Going to check with those who know JS interpreters more intimately...
本文标签: javascriptaccessing the arguments object is expensive huhStack Overflow
版权声明:本文标题:javascript - accessing the arguments object is expensive.. huh? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742269005a2443950.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论