perf(editor): cache fonts extracted from rich text#5735
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
| assert(tipTapConfig, 'textOptions.tipTapConfig must be set to use rich text') | ||
| assert(addFontsFromNode, 'textOptions.addFontsFromNode must be set to use rich text') | ||
| if (isEmptyRichText(richText)) return EMPTY_ARRAY | ||
| return fontsFromTextCache.get(richText, () => { |
There was a problem hiding this comment.
I don't think this is quite right - the fonts found will depend largely on initialState, which encodes stuff like the initial font (from the styles panel). Right now, i think if you change the font, you won't invalidate the cache.
There was a problem hiding this comment.
You can probably see this by removing the font preloading that we do in onMount in Tldraw
There was a problem hiding this comment.
I would add that another concern that the cache would have grown, perhaps, to a large size. Because the rich text would change more often than not (not on every keystroke but maybe in the future it would), we would have a cache that would have needed more work.
|
pushed up the fix @SomeHats |
This PR improves the performance of shapes with rich text content.
The bug
Due to reasons I cannot understand, we extract the fonts from rich text on every frame while translating shapes. Maybe we shouldn't, I don't know. Anyway, this is expensive when many shapes are moving around. Actually, not even that many. Try it yourself!
The fix
The fix here is the same as #5658, which is to skip the work if the text is empt; or use a weak cache to re-use the result from last time.
Change type
bugfiximprovementfeatureapiotherTest plan
Release notes