Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> If I could draw a whole frame in a reasonable amount of time, this problem would be much easier! But I can't. Using Core Text, it can easily take over 150ms to draw a single frame for a 4k display on a 2015 macbook pro.

Holy cow! I wonder if iTerm2 would benefit from using something like pathfinder[1] for text rendering. I mean, web browsers are able to render huge quantities of (complex, non-ASCII, with weird fonts) text in much less than 150ms on OS X somehow; how do they manage it? Pathfinder is part of the answer for how Servo does it, apparently.

[1]: https://github.com/pcwalton/pathfinder



> Using Core Text, it can easily take over 150ms to draw a single frame for a 4k display on a 2015 macbook pro.

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.)


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. gnachman@gmail.com.


"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!


Same reason I love HN. We don't have to guess what the creator was thinking. They'll tell us :-)


Another recent new contender: http://sluglibrary.com

This draws the curves directly in the pixel shader.


I have a bunch of iTerm windows open on my MacBook Pro, I don't want my battery life to suffer


I can't see how it would. The GPU has to be accessed either way, so doing it directly should be the same or better than through an OSX API.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: