Use QStaticText to boost text rendering performance #301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, text rendering in qtermwidget is feature-rich (unicode, font ligatures, etc.) but not fast enough. This change uses
QStaticText
to cache layout information of each text fragment. Since that for typical terminal use case (consider scolling in vim), same text fragments are being rendered repeatedly, caching layout information can save a lot of time. Also, this change does not break font ligatures or unicode.You can easily notice the performance improvement using vim or some other similar terminal applications.
I've been using my terminal with this change as my primary terminal for several weeks now and haven't found any issues.
However there's some changes in the code that may require more discussion:
QStaticText
doesn't work well with underline and strikeout, so I draw them individually insteaddrawStaticText
starts in the top-left corner instead of the baseline, so I didn't find any reliable way to correctly align characters from different fonts (fallback fonts, especially those CJK characters). I now assumes that the height from top to baseline of fallback fonts is 80% of the its total height.LTR_OVERRIDE_CHAR
because, I don't know, it somewhat make the behavior ofQStaticText
incorrect (alignment issue). I don't write RTL text so unfortunately I cannot verify if it breaks anything.