Closed Bug 560995 Opened 14 years ago Closed 13 years ago

TM: specialized iterator for dense arrays without holes

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: gal, Unassigned)

References

Details

Iterating over arrays is a trail of tears. For every iteration, the integer index ("name of the property") has to be stringified, which even for small indexes allocates a string header. For large ones, there is also the integer to string conversion, a malloc, plus the header allocation.

This patch will introduce an optimize iterator for arrays that iterates from n to m (i.e. 0 to length-1). FOR_* pulls a number from the iterator and does IntToString on it. Since my new iterator code moves fetching the next value to the top of the loop, the trace can now reason over the type of this value (including deep inspecting that its really an int).

If we use xeq that bug 560994 will add, we can skip past the IntToString if the loop value is used in a numeric way (i.e. [] or math). This would avoid stringification in many case.
Depends on: 560994
> which even for small indexes allocates a string header.

It does?  We don't use the atomized strings for that?  Maybe we should fix that if so?
I take that back. For small indexes we use pre-defined string headers. For non-small (> 256) we allocate.
Maybe we should patch ValueToNumber to check for those predefined strings and quickly return the number?
We are doing #3 already. But doing the right thing here avoids allocation completely, which is many times faster, an works for all numbers, not just 0..255.
Obsolete with the removal of tracejit.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.