StyledTextKit icon indicating copy to clipboard operation
StyledTextKit copied to clipboard

CATiledLayer for large chunks of text

Open rnystrom opened this issue 6 years ago • 3 comments

Idk how best to combine these, but would improve rendering huge chunks of text.

  • mmap bitmap from disk
  • All layers in memory defeats the purpose
  • LRUCache can store chunks?

rnystrom avatar May 29 '18 12:05 rnystrom

http://www.cimgf.com/2011/03/01/subduing-catiledlayer/

rnystrom avatar May 29 '18 13:05 rnystrom

Yeah, big fan of CATiledLayer for huge chunks of text. However, they are REALLY heavy weight on memory and bad for scroll perf if you have a bunch of them on the screen at once (I tested this awhile ago). In my other text impl I worked on in 2015 in my spare time I came up with the idea of a dual CALayer/CATiledLayer impl that basically uses the layers as stupid shells, and encapsulates logic in a layer render delegate. It's a kind of complicated dance that I'm sure could be simplified.

I pulled the impl from my old project:

https://gist.github.com/ocrickard/9892a28cfd733a84fed95b2a66f27615

Anyway, if you're looking for inspiration, that impl performs great both in tiny little labels, and in huuuge walls of text.

ocrickard avatar Jun 06 '18 22:06 ocrickard

TIL!!

I've never used it before, spared me a lot of time figuring this out lol. I bet the async drawing will be a good quick win. Then if we (or someone else) is hitting huge perf issues from drawing giant bitmaps, then we can find a way to make this work.

rnystrom avatar Jun 10 '18 17:06 rnystrom