Skip to content

perf: cache repeat regexp processing for toShort#57

Merged
caseyahenson merged 1 commit into
joypixels:masterfrom
JoshuaKGoldberg:to-short-cached
Aug 18, 2023
Merged

perf: cache repeat regexp processing for toShort#57
caseyahenson merged 1 commit into
joypixels:masterfrom
JoshuaKGoldberg:to-short-cached

Conversation

@JoshuaKGoldberg

@JoshuaKGoldberg JoshuaKGoldberg commented Apr 7, 2023

Copy link
Copy Markdown
Contributor

Caches the escaped search regex used in ns.toShort, under unicodeCharRegexEscapedSearch(). This way each call to toShort doesn't need to call ns.escapeRegExp on ns.unicodeCharRegex().

Additionally extracts the replacer function used in str.replace to a shared one - that way it can be used in both ns.toShort and ns.replaceAll.

@marvinhagemeister is the one who first prototyped these changes; we'd paired looking at https://github.com/JoshuaKGoldberg/repros/tree/draft-js-emoji-plugin-emoji-toolkit-performance. See #58 for more context.

Fixes #58

Co-authored-by: Marvin Hagemeister hello@marvinh.dev

@JoshuaKGoldberg

Copy link
Copy Markdown
Contributor Author

Ping ... @caseyahenson as last repository commiter? Any chance this PR can be reviewed?

@caseyahenson
caseyahenson merged commit 6337202 into joypixels:master Aug 18, 2023
@JoshuaKGoldberg
JoshuaKGoldberg deleted the to-short-cached branch August 18, 2023 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poor performance when calling toShort repeatedly (uncached repeated regexp processing)

2 participants