New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draw the layer from the background thread #419

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
3 participants
@osheroff
Copy link
Contributor

osheroff commented Nov 23, 2016

during layer draw we know what parts of the screen will need repainting, so we can call set setNeedsDisplayInRect and do a partial draw of the screen. This brings down overall keyDown-to-drawRect(finish) latency when in "layer" mode from 17ms to 4.5ms (about what the "stock" CoreText renderer does).

With this PR, the layer-backed code is about as fast as the standard code (I measured average latency with osheroff@56bb7eb), fast enough that I think we could swap out the old draw-direct code with the layer code, but I thought I would offer that code in a separate PR so you could easily see the methods I'm using here.

cc @splhack @nuc who apparently can feel 10ms of latency much better than I can.

draw the layer from the background thread
during layer draw we know what parts of the screen will need repainting,
so we can call set setNeedsDisplayInRect and do a partial draw of the
screen.  This brings down overall keyDown-to-drawRect(finish) latency
when in "layer" mode from 17ms to 4.5ms (about what the "stock" CoreText
renderer does).
@nuc

This comment has been minimized.

Copy link

nuc commented Nov 23, 2016

Thanks for having a look!

The lag is noticeable if you have really low key repeat delay and for example move the caret around.

I hope that this PR fixes it.
Cheers

@osheroff

This comment has been minimized.

Copy link
Contributor Author

osheroff commented Nov 30, 2016

gentle ping

@splhack

This comment has been minimized.

Copy link
Member

splhack commented Nov 30, 2016

I haven't tested it yet, but do you mind to update this to make sure don't call setNeedsDisplayInRect and setNeedsDisplay if cgLayerEnabled is NO?

@osheroff

This comment has been minimized.

Copy link
Contributor Author

osheroff commented Nov 30, 2016

i can if needs be, but my hope here is that latency is improved enough to simplify the code back down to a single (always-layer-enabled) code path.

@splhack

This comment has been minimized.

Copy link
Member

splhack commented Nov 30, 2016

I might be wrong but we don't need CGLayer for 10.11 or earlier, we may be able to enable it for 10.12 all the time though. And creating helper methods like setNeedsDisplayInRectForCGLayer or something will be still simple enough.

@osheroff

This comment has been minimized.

Copy link
Contributor Author

osheroff commented Nov 30, 2016

two arguments in favor of CGLayer all the time everywhere:

  1. Fixes ugly screen tearing when resizing window (checked this in 10.11, it's happening there too)
  2. Unified code path
@nuc

This comment has been minimized.

Copy link

nuc commented Dec 2, 2016

I tried out the build and it's definitely better than before.

Still, when you hold a key down you feel some lag for a tiny bit, but then it starts to move faster.

👍

@splhack

This comment has been minimized.

Copy link
Member

splhack commented Dec 5, 2016

Merged 2fb08d3

@splhack splhack closed this Dec 5, 2016

@splhack

This comment has been minimized.

Copy link
Member

splhack commented Dec 5, 2016

Enable CGLayer rendering all the time in Core Text Renderer.

defaults write org.vim.MacVim MMUseCGLayerAlways -bool YES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment