-
Notifications
You must be signed in to change notification settings - Fork 20.6k
$.map() fails with large arrays in Сhrome #4320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Applying In an earlier ticket you mentioned that this happened with a templating library. Instead of processing one big template perhaps you could process multiple templates in groups. |
Well, in fact I've just got an error with 130,000 items... Why do you think that it is uncommon? Someone could develop an intranet business application that work with large tables. A table easily could have about 6,500 rows with 10 columns, So you've got 65,000 cells. Each cell could contain two Anyway, the documentation doesn't mention about any limitations. The function
It was not my ticket. I'm concerned that the problem is general for jQuery since it uses |
Nobody should be rendering 6,500 rows on a page simultaneously. That is a good case for pagination or other segmentation techniques like a virtual scrolling window.
There are certainly occasional tickets where people hit these limits in jQuery, but as far as I can recall they have all been in this category of use cases that are unsupported and/or inadvisable.
It's not a limitation in jQuery, it's in Chrome. Firefox works up to at least 500,000. There's got to be a limit somewhere and using a design that hits a rarely-hit limit probably means you're pushing the limits in inadvisable ways. |
I wouldn't be opposed to using native This wouldn't help in IE (and Edge, but that will change soon) by default but:
I'll reopen so that we can discuss it a little more. |
I've just noticed @gibson042's comment at #4318 about exactly this issue where he mentions more cases that'd need to be fixed if that's desired (while watching the size). |
I agree with @fantaclaus. The modern world does not stand still, data volumes, the sizes of pages and monitors grow. Perhaps $ .map () suits you, but your children will say who needs a function like this? |
We haven't been able to spend time on jquery/sizzle#403, but we're thinking that solution can be exposed and used in jQuery to solve this issue. |
Reminder: consider |
I would like to help in resolving this issue. |
@aelafifi Feel free to make a PR! Check out CONTRIBUTING.md if you need some guidance getting started. |
PR: #4459 |
Calling `Array.prototype.concat.apply( [], inputArray )` to flatten `inputArray` crashes for large arrays; using `Array.prototype.flat` avoids these issues in browsers that support it. In case it's necessary to support these large arrays even in older browsers, a polyfill for `Array.prototype.flat` can be loaded. This is already being done by many applications. (cherry picked from 9df4f1d) Fixes jquerygh-4320 Closes jquerygh-4459
When a large array is passed as an argument to
$.map()
we get an error:Tested on Chrome 72 for Windows.
JQuery version: 3.3.1
Sample code:
Internally it calls to
concat.apply
and crashes there.As long as I understand,
apply
tries to push all elements of the array into the stack before invoking the functionconcat
and fails on stack shortage.I believe that any function being invoked thru
apply
with a large array as an argument will fail.I've found about 14 usages of
apply
in the code of jQuery. I would suggest you to check out all of these cases.The text was updated successfully, but these errors were encountered: