最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - accessing the arguments object is expensive.. huh? - Stack Overflow

programmeradmin4浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 14

The 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...

发布评论

评论列表(0)

  1. 暂无评论