Add LRU cache for QTextDocument to MessageDelegateHelperText
ClosedPublic

Authored by mwolff on Mar 29 2020, 1:35 PM.

Details

Summary

Instead of recreating the formatted HTML representation of a message
*and* layouting that in a QTextDocument repeatedly, introduce a
LRU cache and use it in the MessageDelegateHelperText. This patch
noticeably improves the performance of scrolling in chat rooms with
lots of code blocks or other complicated messages.

Diff Detail

Repository
R865 Ruqola
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mwolff requested review of this revision.Mar 29 2020, 1:35 PM
mwolff created this revision.
mwolff updated this revision to Diff 78792.Mar 29 2020, 1:40 PM

only call setTextWidth when needed

Apparently (according to perf) QTextDocument does a relayout when we call
setTextWidth even when the width didn't change... So only call it when needed.

dfaure accepted this revision.Mar 29 2020, 2:55 PM

Very nice!

src/widgets/room/delegate/messagedelegatehelpertext.cpp
330

Nice solution to use std::unique_ptr.
This means you could do the new QTextDocument inside fillTextDocument -- which can then be renamed createTextDocument (I should have done all that),

This revision is now accepted and ready to land.Mar 29 2020, 2:55 PM
mwolff updated this revision to Diff 78808.Mar 29 2020, 8:11 PM

fillTextDocument -> createTextDocument

dfaure accepted this revision.Mar 29 2020, 8:32 PM
This revision was automatically updated to reflect the committed changes.