perf(activity): cache singleton pointers and avoid string concat in hot path#9997
Open
qoole wants to merge 1 commit intonextcloud:masterfrom
Open
perf(activity): cache singleton pointers and avoid string concat in hot path#9997qoole wants to merge 1 commit intonextcloud:masterfrom
qoole wants to merge 1 commit intonextcloud:masterfrom
Conversation
…ot path - ActivityListModel::data: cache FolderMan::instance() once per role evaluation instead of dereferencing the singleton twice for every row that has a file path. The Roles::PathRole and getDisplayPath lambda each used to call FolderMan::instance() twice; now once. - ActivityListModel::convertLinkToActionButton: move the reply icon URL construction inside the isReplyIconApplicable branch, and bake the trailing slash into the QStringLiteral so the path is a single immutable literal instead of two QString::operator+ allocations per activity link. - User::slotRefresh: cache _account.data() once and reuse instead of calling .data() five times in a row. Slight readability improvement alongside the avoided refcount manipulations. Signed-off-by: Qoole <2862661+qoole@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Three small allocation/dereference cleanups in the activity list and user model. Each one is per-row or per-refresh, and the activity list
data()runs on every visible row of every model update.ActivityListModel::data— cacheFolderMan::instance()Two places in
data()dereference theFolderMansingleton twice in succession:Cached the pointer once per role evaluation. Same behavior, half the singleton lookups.
ActivityListModel::convertLinkToActionButton— reply icon URLTwo improvements bundled:
replyButtonPathwas constructed unconditionally even whenisReplyIconApplicableis false. Moved inside the branch.QStringLiteral(".../reply.svg") + "/", allocating a QString concat every call. Baked the trailing slash into the literal so it's a single immutableQStringLiteral.Same URL on the wire; one allocation removed per applicable activity link.
User::slotRefresh— cache_account.data()slotRefreshwas calling_account.data()five times in a row. Cached once into a localauto *account. Behavior identical (the smart pointer is already strong-rooted onthis->_accountfor the duration of the function).Checklist
AI (if applicable)