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.
I noticed escape.js used an object lookup. Since the object is static and small it would in theory be notably faster to unroll this.
https://jsperf.app/gunane/1/preview
underscoreEscape
is the code as it is now in main.ifEscapeWithTest
is as it is in this PR. Per that test run, that should make this implementation ~14% faster in my setup. The improvements were more notable on much shorter input.I left in the
.test
call but I am not sure why it's present. I assume it's to reduce allocations? It's not free but in my testing it only adds an additional "1%" (ifEscape
isifEscapeWithTest
but without that) even though its positive path is not hit in my benchmarking.I noticed my random sampling of files showed they used 4 space indentation, but I followed https://github.com/lodash/lodash/blob/main/.github/CONTRIBUTING.md which said to use 2 space indentation.
Code from benchmark: