访问参数对象很贵..呵呵? [英] accessing the arguments object is expensive.. huh?

查看:58
本文介绍了访问参数对象很贵..呵呵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说很多人说访问参数对象很昂贵。 (例如:为什么arguments.callee.caller属性在JavaScript中已弃用?

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?

推荐答案

重要的事情至少有两个:

The big deal is at least twofold:

1)访问arguments对象必须创建一个arguments对象。特别是,每次调用函数时,现代JS引擎实际上并不为参数创建新对象。它们在堆栈上传递参数,甚至在机器寄存器中传递参数。但是,只要触摸参数,就必须创建一个实际对象。这不一定便宜。

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)触摸参数对象后,JS引擎可以执行的各种优化(例如,检测您从未分配给参数的情况)并优化那种常见情况)走出窗外。每次访问函数参数,而不仅仅是通过参数的访问变得慢得多,因为引擎必须处理你可能通过<$ c $搞乱了参数的事实。 c>参数。

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 common case) go out the window. Every access to the function arguments, not just ones through arguments becomes much slower because the engine has to deal with the fact that you might have messed with the arguments via arguments.

这篇关于访问参数对象很贵..呵呵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆