Skip to content

perf: Add timestamp to msgs_index7 and speed up Chatlist::try_load()#8406

Open
iequidoo wants to merge 3 commits into
mainfrom
iequidoo/chatlist-speedup
Open

perf: Add timestamp to msgs_index7 and speed up Chatlist::try_load()#8406
iequidoo wants to merge 3 commits into
mainfrom
iequidoo/chatlist-speedup

Conversation

@iequidoo

@iequidoo iequidoo commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

This speeds up chatlisting by 3--4 times on my biggest profile, so the difference is visually
noticeable, particularly after dropping disk caches. Before, msgs_index2 was used which has less
ordering and requires a full scan of msgs table.

explain query plan output for the "normal chatlist":

QUERY PLAN
|--SEARCH c USING INTEGER PRIMARY KEY (rowid>?)
|--SEARCH m USING INTEGER PRIMARY KEY (rowid=?) LEFT-JOIN
|--CORRELATED SCALAR SUBQUERY 1
|  |--MULTI-INDEX OR
|  |  |--INDEX 1
|  |  |  `--SEARCH msgs USING COVERING INDEX msgs_index7 (state=? AND hidden=? AND chat_id=?)
|  |  `--INDEX 2
|  |     `--SEARCH msgs USING COVERING INDEX msgs_index7 (state=? AND hidden=? AND chat_id=?)
|  `--USE TEMP B-TREE FOR ORDER BY
`--USE TEMP B-TREE FOR ORDER BY

Fix(?) #7848 . But even if not, this is an improvement anyway and i think that in general we should avoid full scans of msgs, it's the biggest table and otherwise the app doesn't scale well over time without DeleteDeviceAfter set.

@iequidoo iequidoo force-pushed the iequidoo/chatlist-speedup branch from 453dcae to 218dd1a Compare July 7, 2026 14:11
@iequidoo iequidoo marked this pull request as ready for review July 7, 2026 15:17
@iequidoo iequidoo force-pushed the iequidoo/chatlist-speedup branch from 218dd1a to 1909a16 Compare July 7, 2026 16:19

@WofWca WofWca left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look at the code, but I have a nitpick about the commit message: pefr: prefix would be more appropriate I think. I have checked that it's used in this project, git log --grep="perf:".

@iequidoo iequidoo changed the title feat: Add timestamp to msgs_index7 and speed up Chatlist::try_load() perf: Add timestamp to msgs_index7 and speed up Chatlist::try_load() Jul 11, 2026
iequidoo added 3 commits July 11, 2026 10:26
…7848)

This speeds up chatlisting by 3--4 times on my biggest profile, so the difference is visually
noticeable, particularly after dropping disk caches. Before, `msgs_index2` was used which has less
ordering and requires a full scan of `msgs` table.
Not clear why `GROUP BY` was needed -- a chat can't appear in the selected rows multiple times
because we do JOIN on the last message in the chat, there can't be multiple last messages.
@iequidoo iequidoo force-pushed the iequidoo/chatlist-speedup branch from 1909a16 to 8e506f9 Compare July 11, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants