Emoji plugin - initial import is slow
dugancathal opened this issue · comments
Environment
OS: MacOS 13.4.1
Browser: Chrome 115, Firefox 116
@draft-js-plugins/emoji version: ^4.6.5
draft-js version: ^0.11.7
Description
When testing the Emoji plugin locally (and on the draft-js-plugins demo site),
we see that it takes upwards of 2 seconds to build mappings from shortname to
unicode and back again. These mappings are built on initial import. For us,
as we import the library early on, this slows down time to First Contentful
Paint to a level that's unnacceptable for our application. It's also notable
on the Emoji demo site.
In performance exploration, we found that the emoji plugin leverages the
toShort function (from emoji-toolkit) heavily to convert from unicode to
the shortname. The plugin previously also mapped from shortname to unicode
separately. This double-mapping appears to be the primary cause of the
slowdown (for the useNativeEmoji option, at least).
Note: timings in the screenshots from a 2022 MacOS M1 running latest Google Chrome,
but this appears to be replicable on Firefox as well.
Reproducible Demo
This is reproducible on the demo site: https://www.draft-js-plugins.com/plugin/emoji
Performance profile before
![Screenshot 2023-08-03 at 8 45 53 AM](https://private-user-images.githubusercontent.com/1172512/258189354-8995e953-1557-471b-a1d6-b8c5b0195bbe.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyOTYyODUsIm5iZiI6MTcxOTI5NTk4NSwicGF0aCI6Ii8xMTcyNTEyLzI1ODE4OTM1NC04OTk1ZTk1My0xNTU3LTQ3MWItYTFkNi1iOGM1YjAxOTViYmUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjVUMDYxMzA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZTRiMjc3MWZhYjhkNDU1ZmJhZDNkOGUwOGZmNjY5MDcyOWFlZTRjNTc2NWFiNWRlOTVlMTZiY2M0NGI0YWZjZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.xHaUd1GPNfpN_5t2bqGTY1OI2OrHsIFYlFMLs0TY-80)
Performance profile after
![Screenshot 2023-08-03 at 8 48 01 AM](https://private-user-images.githubusercontent.com/1172512/258189446-e08ff8a4-2f43-4c38-923c-fe0c97517ed0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyOTYyODUsIm5iZiI6MTcxOTI5NTk4NSwicGF0aCI6Ii8xMTcyNTEyLzI1ODE4OTQ0Ni1lMDhmZjhhNC0yZjQzLTRjMzgtOTIzYy1mZTBjOTc1MTdlZDAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjVUMDYxMzA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZTQxYWYwMmM3YWMzYmMyNjllYTFhNzE3YTFkYjkzZDBjOWY0NTg1MGRjZWViMGM4YTM4ZGQ1ZWUwMTgzYWZjZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.HBvGA40MiHl79zeg2FdpW4oPd5ZATE7AU8xGi0sE7Gg)