Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JoshuaKGoldberg opened this issue Apr 7, 2023 · 0 comments · Fixed by #57

Comments

@JoshuaKGoldberg
Copy link
Contributor

👋 I learned about this project recently - it's very useful, thanks for publishing it!

emoji-toolkit is used in the emoji plugin for Draft.js. That plugin calls to emoji-toolkit's toShort repeatedly, on each emoji in emojibase-data/en/compact.json [shortnameToUnicode.ts link].

Doing so results in ~2 seconds processing time (!) (Mac Studio M1 Max), largely spent in escapeRegexp. You can see a full breakdown of the investigation here: https://github.com/JoshuaKGoldberg/repros/tree/draft-js-emoji-plugin-emoji-toolkit-performance#description-of-issue

1.689.3ms annotation on the first return in emoji-toolkit's escapeRegexp]

@marvinhagemeister and I took a look at it and found that replaceAll was calling ns.escapeRegExp repeatedly on the same regular expression cached by unicodeCharRegex. Changing toShort to not need that call reduced that processing time to <200ms.

I took the liberty of sending #57 preemptively - hope that's ok with you! 🙂

Since GitHub doesn't support uploading .json files directly, here's a .zip with before & after profiles: Performance Profiles.zip

@JoshuaKGoldberg JoshuaKGoldberg changed the title Poor performance when calling toShort (uncached repeated regexp processing) Poor performance when calling toShort repeatedly (uncached repeated regexp processing) Apr 7, 2023
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 a pull request may close this issue.

1 participant