Thanks for the response. I have beat my head against a wall for months trying to get to the bottom of this. I already tried and abandoned using multiple threads within drawRect:, and I agree there is a global lock :). For the case I benchmark there are no bitmaps besides NSFillRect on the background color (which is surprisingly slow, but unavoidable without doing something weird like drawing background colors on a separate layer).
I've confirmed that I always use the same NSFont in the attributed string used to create the CTLineRef.
If you're curious, the text drawing code is in drawTextOnlyAttributedStringWithoutUnderline:atPoint:positions:backgroundColor:graphicsContext:smear: and is located here: https://github.com/gnachman/iTerm2/blob/master/sources/iTerm...
If you're able to spare some cycles, please get in touch with me. [email protected].
"iTerm2 author here"
...
"(I'm the author of Pathfinder.)"
I keep thinking that sometime soon the magic of HN will wear off, or we will hit "peak hackernews" or something like that.
Not today!
Re:Terminal and shell performance
by nkristoffersen on Wednesday July 19, 2017 @03:30AM
(#14802542)
Same reason I love HN. We don't have to guess what the creator was thinking. They'll tell us :-)
I'm guessing that you're somehow preventing Core Text from taking advantage of its caching. Apple's APIs can be a bit fussy about their internal caches; for example, the glyph cache is (or at least used to be) a global lock, so if you tried to rasterize glyphs on multiple threads you would get stalls. Try to reuse Core Text and font objects as much as possible. Also check to make sure you aren't copying bitmaps around needlessly; copying around 3840x2160 RGBA buffers on the CPU is not fast. :)
For a terminal, all you really need to do for fast performance is to cache glyphs and make sure you don't get bogged down in the shaper. Pathfinder would help when the cache is cold, but on a terminal the cache hit rate will be 99% unless you're dealing with CJK or similar. There's a lot lower hanging fruit than adopting Pathfinder, which is undergoing a major rewrite anyway.
(I'm the author of Pathfinder.)