forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: don't recompile escapeRegExp for every query
Context: the query builder is pretty CPU intensive, and can be slow - e.g. typeorm#3857 One of the things which makes this slow is `escapeRegExp` in the query builder: we freshly construct the same RegExp once per `replacePropertyName` invocation (many times per overall query!) and since the RegExp itself is constant -- we can lift it out and construct it once. Over-all this saves about 8% on our query build times as measured by typeorm#8955.
- Loading branch information
Showing
2 changed files
with
6 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Escape special characters in regular expressions | ||
// Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping | ||
const ESCAPE_REGEXP = /[.*+\-?^${}()|[\]\\]/g | ||
export const escapeRegExp = (s: String) => s.replace(ESCAPE_REGEXP, "\\$&") |