Thanks for filing an issue! Please answer the questions below so I can help you.
iTerm2 version: Build 3.0.20160720-nightly
OS version: 10.11.3
Attach ~/Library/Preferences/com.googlecode.iterm2.plist here (drag-drop from finder into this window) (I'm executing the nightly build directly from the Downloads folder so I don't know if the ~/Library/Preferences/com.googlecode.iterm2.plist belongs to the nightly build or to the other version I have installed. Please advise)
If it matters, I'm using Neovim with termguicolors enabled, and the full window is 293x95. The videos are Neovim running in tmux with 3 vertically split panes to the right with no text in them besides the shell prompt. This is over local SSH to an Ubuntu server.
It seems strange that the performance is drastically affected in tmux. The performance is reasonable using tmux integration, but it's something I can't get used to without the ^b prefix.
Yeah, it's Neovim. Didn't realize you couldn't drag the status bars in Vim
I only used it as a example since it was easy to visually convey the problem. The performance is about the same if you scroll in a tmux pane or there's fast output printing. It's made worse if there's a lot of colored text.
I've spent quite a bit of time working on this, but no big wins so far. For future reference:
Draw text in multiple threads
Since text rendering is where we spend most of our time, I tried rendering text in a concurrent dispatch queue. Unfortunately the overhead of compositing it back into the graphics context canceled out the win from getting parallel rendering. I first tried CGContextDrawImage, which was horrible, and then CGLayer, which was fast but creating the layers was slow enough to exactly cancel out the performance benefit. This effort is in the parallelDrawing branch.
Create attributed strings and CTLineRef in multiple threads
The next-slowest part is creating attributed strings and core text lines. It's not that slow, though. Moving it into a concurrent queue didn't provide a measurable improvement. The overhead of shuffling between queues equaled the benefit from parallelism. This effort is in the parallelBuilder branch.
Use CALayers
Giving PTYTextView a layer kills performance, presumably because the layer is enormous. Giving SessionView a layer actually helps by about 10%! But it breaks transparency. So the next step is to make the layer present only when there's no transparency.
Next steps
What I haven't figured out yet is where all the time goes. If drawRect takes 0.3 seconds then the time between calls is like 0.46 seconds. Instruments shows 75% of main thread time is spent in drawRect but only 83.3% of main thread time is in my own code. I guess the rest of the time is copying pixels among internal buffers, which I have no control over. If I could just get a little more work done between -drawRect calls it would be lovely.
I just made a few commits that should help. Please try tomorrow's nightly build. You'll get the best performance bump if you use a font that does not have ligatures (so avoid Hasklig, PragmataPro, and OperatorMono).
Note to self: I still need to put a layer on SessionView when there is no transparency.
@ahmedelgabri There's still some improvement with ligatures, but not as much as without them. The problem is to get ligatures I have to render with CoreText. It is several times slower than rendering text with Core Graphics. The optimization I made was to use Core Graphics for letters and numbers, which don't usually get ligatures, and Core Text for symbols and non-ASCII text. The ball's in Apple's court as far as I can tell. Terminal.app uses a dynamic refresh rate like iTerm2's adaptive refresh rate to work around the issues with CoreText's slowness.
Everyone please test the latest nightly build and let me know if you get weird rendering issues or missing ligatures. If you do, please attach your $HOME/Library/Preferences/com.googlecode.iterm2.plist to this issue with a screenshot.
@gnachman Just installed it & it's much better than before even with a ligatures enabled font, using Fira Code in my case, not as smooth as normal fonts but way better than before & I can live with that. I'll keep any eye on any rendering issues or missing ligatures.
@ahmedelgabri I'd like to reproduce the sluggishness you report:
What kind of hardware are you on?
Can you provide a session log? Open a new tab, do Session>Log>Start, record yourself working for a while, Session>Log>Stop, and attach the log file here.
The font with sluggishness is Fira Code, I presume?
MacBook Pro (Retina, 15-inch, Mid 2015) running macOS sierra 10.12.1
I couldn't get the latest nightly build working at all, It just kept crashing, will try again later today hopefully. I tried:
with a clean com.googlecode.iterm2.plist instead of my own
tried installing it directly from the website instead of homebrew cask.
removing iterm2 files completely using brew cask zap iterm2-nightly or brew cask zap iterm2 or using App Cleanerwhen I installed it through the website.
I have a theory that there were unnecessary redraws when the cursor's visibility changed. The cursor will probably do funky things in this build, but I'm just interested in knowing if it helps with the performance issues you see.
@gnachman Been using that build that you sent nearly the whole day & it's definitely better than before. Still not as fast as when not using a font with ligatures. Older versions were not even usable for a couple of mins.