ChimeHQ / Neon

A Swift library for efficient, flexible content-based text styling
BSD 3-Clause "New" or "Revised" License
325 stars 18 forks source link

Computing visible range sets can be very expensive #50

Closed mattmassicotte closed 1 month ago

mattmassicotte commented 1 month ago

TextViewSystemInterface.visibleSet can be an expensive call. Actually computing the visible range in TextKit 1 doesn't seem to be an issue, but the system is spending a lot of time transforming this range into a set.

I wonder if caching could help here.

mattmassicotte commented 1 month ago

Learnd a few things.

mattmassicotte commented 1 month ago

Ok so while Glyph's implementation definitely is superior in a number of ways, the core problem was caused by the initializer.

let range = NSRange(0..<1_000_000)

// this is very slow
_ = IndexSet(range)

// this is very fast
_ = NSIndexSet(indexesIn: range) as IndexSet

So now this now very much better with f3c717b5bbf2118aa93f16a0aa4adf9a9c39ad43