-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: loop over arguments instead of spreading #2160
Conversation
I'm unfamiliar with the code, but wondered if the target is already an array, would |
@CaptainCodeman yea that's a good point. I've seen various arguments for using |
@leibale thanks for the link! Looks like spread and concat are pretty comparable so I updated to use concat |
@leibale anything else I can do to help get this merged? |
@bmeverett I'm not too sure if |
@leibale so just to clarify, the main goal of this PR isn't necessarily performance, although I can see that it may come into play. I believe @CaptainCodeman was just asking about performance from my implementation. The main issue is that MDN warns about using large values for spread.
I am now using Happy to discuss further or clarify anything. |
I'm also concerned that the const args = ['Hello'];
pushVerdictArguments(args, ['World']);
console.log(args); will break (with the I'll try to find another way to solve it (without decreasing performance) tomorrow. |
It just looked like the sort of thing where an inbuilt method might / should beat a loop, but from what I've read it seems that concat perf wins only when dealing with very large arrays. There's probably some cross-over point where it could use one or the other (?) Another option to try would be batching the pushes as slices so there weren't as many loop iterations - no idea if it would be faster or not, the V8 engine may optimize the simple loop better than anything else. |
… it'll push to the original array)
@bmeverett review my changes please? 🙏 |
…' is not assignable to parameter of type 'RedisCommandArgument | RedisCommandArgument[]'"
@leibale looks good to me! Thanks for the updates! |
Description
Pushing a large number of arguments (100ks) to a command causes a
RangeError: Maximum call stack size exceeded
.This is caused by using the spread operator since javascript can't hold all the values in memory. This updates to loop over the passed in array and add the values in a loop instead of using spread.
Checklist
npm test
pass with this change (including linting)?