Issue 1451 in v8: Array.forEach, filter, some, etc. are not special-cased for sparse arrays.

10 views
Skip to first unread message

codesite...@google.com

unread,
Jun 10, 2011, 11:53:19 AM6/10/11
to v8-...@googlegroups.com
Status: New
Owner: ----

New issue 1451 by floit...@google.com: Array.forEach, filter, some, etc.
are not special-cased for sparse arrays.
http://code.google.com/p/v8/issues/detail?id=1451

Array.forEach, filter, some, every, map, reduce and reduceRight don't
special-case for sparse arrays. They loop from 0 to length-1.


codesite...@google.com

unread,
Jun 14, 2011, 1:59:11 AM6/14/11
to v8-...@googlegroups.com

Comment #1 on issue 1451 by a...@chromium.org: Array.forEach, filter, some,
etc. are not special-cased for sparse arrays.
http://code.google.com/p/v8/issues/detail?id=1451

The reason they loop without attempting to special case for sparse arrays
is that the callback function can add elements to the array being iterated.
These are supposed to be included in the iteration. Therefore we cannot
compute the indices up front as we do with other array methods. We need a
mechanism to bail out when an element is added.

codesite...@google.com

unread,
Oct 2, 2012, 12:45:50 PM10/2/12
to v8-...@googlegroups.com

Comment #2 on issue 1451 by middenv...@gmail.com: Array.forEach, filter,
some, etc. are not special-cased for sparse arrays.
http://code.google.com/p/v8/issues/detail?id=1451

Getting out of memory problems in Node for this.

Problem occurs with a very large sparse array - first index value that is
not undefined is in the millions.

With code of the form below, the debug statement never appears and an out
of memory error is reported after a couple of minutes.

var res = this.sparse.filter(function(x,i,a)
{
logger.debug(x);
return (x.isLoggedOn && (x.smallArr.indexOf(groupId) != -1));
});


codesite...@google.com

unread,
Feb 5, 2015, 8:59:23 AM2/5/15
to v8-...@googlegroups.com
Updates:
Status: PendingFurtherInfo

Comment #3 on issue 1451 by habl...@chromium.org: Array.forEach, filter,
some, etc. are not special-cased for sparse arrays.
https://code.google.com/p/v8/issues/detail?id=1451

Update done during clean-up of issue tracker.

I could not reproduce it as the definition and initialization of sparse is
missing. Can you please add it if the problem still exists?

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

codesite...@google.com

unread,
Feb 5, 2015, 11:19:02 AM2/5/15
to v8-...@googlegroups.com
Updates:
Status: WorkingAsIntended
Owner: a...@chromium.org
Cc: ad...@chromium.org

Comment #4 on issue 1451 by a...@chromium.org: Array.forEach, filter, some,
etc. are not special-cased for sparse arrays.
https://code.google.com/p/v8/issues/detail?id=1451

Also, optimizing for this does not seem very useful. Sparse arrays are bad
and performance sensitive code never uses this.

codesite...@google.com

unread,
Feb 10, 2015, 1:16:12 PM2/10/15
to v8-...@googlegroups.com

Comment #5 on issue 1451 by middenv...@gmail.com: Array.forEach, filter,
some, etc. are not special-cased for sparse arrays.
https://code.google.com/p/v8/issues/detail?id=1451

Using a sparse array for something that is easily hashable - such as an
IPv4 address, or in this case, a similar machine identifier, is an obvious
thing to do in Javascript. There is nothing in the Javascript spec that
indicates large key values are deprecated - that is actually a useful
feature of the Javascript array.
Reply all
Reply to author
Forward
0 new messages