rajdeep / proton

Purely native and extensible rich text editor for iOS and macOS Catalyst apps
Other
1.25k stars 81 forks source link

Cache image list markers #303

Closed erudel closed 3 months ago

erudel commented 3 months ago

Problem: when an editor contains many list items that are represented by the same image marker, there is a substantial amount in the layout pass spent resizing the image to the given size.

Solution: since the markers and sizes are the same for list items, we can cache the resized image and reuse it for successive calls. In some cases the number of calls to resize images went from ~7700 to just 4.

The implementation uses a Dictionary to store a cache for each image, and the cache is keyed by the size. I tried creating a cache with a single key derived from the image and size, however the string interpolation turned out to be more expensive than this approach.

I profiled the rendering before/after the change and here are the results:

Before:

before cache

After:

after cache