Skip to content

feat: 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

feat: 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 added 3 commits July 7, 2026 13:19
…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 218dd1a to 1909a16 Compare July 7, 2026 16:19
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.

1 participant