Skip to content
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

Conversation

@osheroff
Copy link
Contributor

@osheroff 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.

Ben Osheroff
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
Copy link

@nuc 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
Copy link
Contributor Author

@osheroff osheroff commented Nov 30, 2016

gentle ping

@splhack
Copy link
Contributor

@splhack 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
Copy link
Contributor Author

@osheroff 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
Copy link
Contributor

@splhack 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
Copy link
Contributor Author

@osheroff 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
Copy link

@nuc 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
Copy link
Contributor

@splhack splhack commented Dec 5, 2016

Merged 2fb08d3

@splhack splhack closed this Dec 5, 2016
@splhack
Copy link
Contributor

@splhack 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
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants