Avoid slowdown from URL#searchParams
in glob embed
#94
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.
Type of Change
What issue does this relate to?
Relates to #92
What should this PR do?
URL#searchParams#append
seems to have terrible performance when working with a large number of parameters, across different runtimes and browsers: https://twitter.com/MattIPv4/status/1748102513646047584 (https://twitter.com/MattIPv4/status/1748116227703099900)While it is unlikely in regular use that the glob embed would encounter enough tests being provided for this to actually be an issue, it was reported as a potential attack vector in the library.
As such, this PR switches us over to a more old-fashioned approach of using
encodeURIComponent
in a loop, which shouldn't risk any drastic performance issues in such an edge case.This also includes a minor refactor of the glob regex that was fixed in #92 so it is easier to follow what is happening in it.
What are the acceptance criteria?
Glob embeds continue to parse and generate as expected, with no performance bottleneck from the new test with a large number of tests provided.