Don't allocate an arguments object in strict function calls when not necessary

RESOLVED WORKSFORME

Status

()

Core
JavaScript Engine
RESOLVED WORKSFORME
5 years ago
5 years ago

People

(Reporter: David Bruant, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
Refers to an es-discuss thread [1][2] (just here for reference, it's not necessary to read to understand the bug)
In a strict function, it's possible to prove that the "arguments" won't be used (if neither 'arguments' nor 'eval' appear in the function body). It costs a one-time full-function-body analysis (can even be done in a different thread), but once proven, all calls to the function can be cheaper because they don't need to allocate the arguments object at all.
I think we can decently assume that most JS functions don't use neither 'arguments' nor direct eval, so it seems worth it.

A couple of questions:
1) does the current implementation always allocate an arguments object for all function calls?
2) Is the suggested optimization already performed?

[1] https://mail.mozilla.org/pipermail/es-discuss/2012-December/026868.html
[2] https://mail.mozilla.org/pipermail/es-discuss/2012-December/026893.html

Comment 1

5 years ago
Unless I'm missing what you're saying, we already do this.  We even avoid creating an arguments object if the function *does* mention 'arguments' but only uses 'arguments[i]' and 'arguments.length' and there are no writes to formals.
> 1) does the current implementation always allocate an arguments object for all function
> calls?

No.

> 2) Is the suggested optimization already performed?

Hard to say what exactly the suggested optimization is.

Right now we detect whether a function might need an arguments object.  Note that just using arguments[i] does NOT on its own force creation of an arguments object, because it can compile to direct access to the arglist, unless there's weirdness going on (vars aliasing arguments, etc).  If we decide the function doesn't need an arguments object, it's not created (and some other stuff; for example right now Ion will only compile functions that don't need an arguments object).

Comment 3

5 years ago
Closing WFM based on comment 1 and comment 2.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.