Repository navigation
Conversation
ParameterizedSQL.join builds the joined SQL and one fresh params array in a single pass. Appending each statement through ParameterizedSQL.append copied the accumulated params array once per statement, so building an inq/nin clause over N values cost O(N^2): 35,000 values blocked the event loop for about 2.3 s. The params arrays of the joined statements are left untouched, since the constructor keeps the caller's array by reference. Fixes loopbackio#1003 Signed-off-by: MaolmeoX <arnaud.maurice.pro@gmail.com>
MaolmeoX
marked this pull request as ready for review
November 9, 2026 10:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParameterizedSQL.joinbuilds the joined SQL and a single fresh params array in one pass, instead of callingParameterizedSQL.appendonce per statement, which copied the accumulated params array every time. Everyinq/ninclause goes throughjoinwith one statement per value, so the cost was quadratic in the number of values.Measured on Node 24.19 with the script from the issue:
buildWherewith aninqof 35,000 ids goes from 2,318 ms to 24 ms.The output is unchanged: same separator handling (including statements with an empty
sql), same params order, and plain strings and{sql, params}objects are still normalized through the constructor. 20,000 random joins compared old against new produced identical results. The params arrays of the joined statements are not modified: the constructor keeps the caller's array by reference, so the result gets its own array.Tests added in
test/sql.test.js: the joined result for mixed input, the joined statements' params left untouched, and a join of 50,000 statements under a 1 s mocha timeout. That last test takes about 5 s and fails on the current code, and about 20 ms with this change.Fixes #1003
Checklist
npm testpasses on your machine