-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Reduce text layout CPU usage when DWrite analysis is not needed #2959
Reduce text layout CPU usage when DWrite analysis is not needed #2959
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
67b047d
to
e566a4a
Compare
Seems something wrong with the format. But I can't really tell what it is. |
@skyline75489 It's probably the |
@zadjii-msft Thanks! I'll give it a try. This PR is crucial almost the entire "make cmatrix great again" movement. Would love to see it merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me, but I don't think I want this in w/o @miniksa's sign off on it, since he knows the renderer best.
src/renderer/dx/CustomTextLayout.cpp
Outdated
// Perform our custom font fallback analyzer that mimics the pattern of the real analyzers. | ||
RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength)); | ||
const bool whiteSpacesOnly = std::all_of( | ||
_text.begin(), _text.end(), [](wchar_t c) noexcept { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, can we just pass &iswspace
as the function? (my c++17-fu is not strong so this is mostly an educational question).
(and the same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeal it could be &iswspace
. It's just initially the condition here is a little more than a simple function. So I left it here.
I'd also love to here from some one who knows this more. I'm afraid some of the optimization could be to aggresive. So no need to rush it.
I would prefer to always lean on further portions of the DirectWrite framework to analyze the text, determine complexity, or figure out which regions we can discard before calling an expensive function. I really don't want to mix in other technologies like the CRT here. If we don't know the right way to do something in DWrite, I'd rather lean on our internal contacts on those teams to help us figure it out than try to reverse it with a mix of other technologies. Overall, though, I think this particular CPU concern is just majorly an artifact of #778 being incomplete. |
@miniksa I agree with you on that #778 is the ultimate solution for overall performance. However, I'd argue that this optimization is still needed even #778 is complete. There are still many situations that requires entire screen redrawing(e.g. vim, cat, and less). Differential drawing won't optimize away the CPU burden with all those DWrite analysis. I'm not a DWrite expert and I chose CRT on this one. Seems |
5300144
to
9547cbd
Compare
9547cbd
to
72712da
Compare
The concern I have on this, is what will |
I found a catch. If I open |
I added the check of text read length to eliminate the issue with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this now. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize that we backed out our complexity analysis. Yeah, this is awesome. Thank you!
🎉 Handy links: |
Hrm, I remember someone saying somewhere that Safari uses a similar trick to save on layouting and that it can lead to tricky edge-cases with font features. A terminal is probably less likely to deal with OpenType Layout data in fonts, so it might be okay 🤔 |
## Summary of the Pull Request As the title suggests, this PR will make CustomTextLayout skip glyph shaping analysis when the entire text is detected as simple. ## References My main reference is [DirectX Factor - Who’s Afraid of Glyph Runs?](https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/november/directx-factor-who%e2%80%99s-afraid-of-glyph-runs) And also #2959 ## PR Checklist * [x] Closes @skyline75489's continuous drive for perf gainz. * [x] CLA signed. * [x] Manual tests. * [x] Nah on docs. * [x] Discussed with core contributors in this PR. ## Detailed Description of the Pull Request / Additional comments This can be seen as a followup of #2959. The idea is the same: make use of simple text (which makes up I think 95% of all terminal text) as much as possible. The performance boost is huge. Cacafire is actually on fire this time (and remember I'm using 4K!). The frame rate is also boosted since more CPU time can be used for actual drawing. Before:  After:  ## Validation Steps Performed Manually validated.
Summary of the Pull Request
It takes many CPU cycles to calculate text layout & font fallback even it's not really necessary. This may seem a little aggresive but it indeed dramatically boost performance.
References
#806
PR Checklist
Detailed Description of the Pull Request / Additional comments
With the help of #2937 and this PR, vim performance is way more smooth than before.