-
Notifications
You must be signed in to change notification settings - Fork 949
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
[select] use for loop instead of push.apply
#403
Comments
@timmywil If perf does become an issue and you find a significant difference with large work loads, another compromise might be to batch it. At Wikimedia, variations of the following utility exist in a few larger projects. /**
* Push one array into another.
*
* This is the equivalent of arr.push( d1, d2, d3, ... ) except that arguments are
* specified as an array rather than separate parameters.
*
* @param {Array|ve.dm.BranchNode} arr Object supporting .push(). Will be modified
* @param {Array} data Array of items to insert.
* @return {number} Length of the new array
*/
ve.batchPush = function ( arr, data ) {
// We need to push insertion in batches, because of parameter list length limits which vary
// cross-browser - 1024 seems to be a safe batch size on all browsers
var length,
index = 0,
batchSize = 1024;
if ( batchSize >= data.length ) {
// Avoid slicing for small lists
return arr.push.apply( arr, data );
}
while ( index < data.length ) {
// Call arr.push( i0, i1, i2, ..., i1023 );
length = arr.push.apply(
arr, data.slice( index, index + batchSize )
);
index += batchSize;
}
return length;
}; |
Any update when this issue will be fixed ? |
https://jsperf.com/arraylike-push-many With array-like objects, When the receiver is an array instead of an ordinary object, though, Firefox, Edge, and sometimes IE penalize simple assignment by up to 20%, and Safari's performance drops by an order of magnitude. So the only consistently good option is |
Has there been any update / movement on this issue? Seeing these errors occur randomly throughout our app, and tracing the error led me to this particular issue in Sizzle |
This test case is 404 now, do you have a copy? |
There's a jQuery PR for this issue now: jquery/jquery#4459 |
Any movement on this? It's still causing "stack limit exceeded" errors in the latest versions of jquery e.g. from 3.6.0:
|
jQuery version at jquery/jquery#5298 |
Migrated from jquery/jquery#3704
We decided in the meeting to try a for loop instead of
push.apply
. Check perf to be sure, but for loops are so heavily optimized these days that it might even be better. It has the added advantage of not causing "stack limit exceeded" errors.The text was updated successfully, but these errors were encountered: