You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
messages sync slows from ~75 to ~7 messages/s as the store grows; time goes to local processing #917
During a long messages sync of one large supergroup, throughput falls steadily as the store grows, from ~75 messages/s to ~7 messages/s. Telegram is not the bottleneck: one page of 100 messages arrives in ~270 ms. The time goes to local processing; on 0.134.0 the sync process sits at 100% CPU. At this rate, the remaining ~570k messages of the chat take about a day.
Foreground run on 0.134.0, 500 messages: 67 s wall, 41 s user, 21 s sys.
Same chat, same time, --trace on a single messages list --limit 100:
{"event":"response","operation":"messages.list","duration_ms":272,"outcome":"ok","counts":{"messages":100}}
not saved to the local store: database is locked
real 6.75
So a page costs ~0.3 s at Telegram, 1 s of default --pause, and ~13 s locally. While the sync ran, store status took ~6 s and other commands could not write (database is locked). On 0.99.0 the sync process showed ~0% CPU when sampled, so it may have been waiting on I/O or locks there; on 0.134.0 it is CPU-bound.
The per-page cost grows with the number of stored messages, so something in the write path appears to scale with the store or the chat's stored history rather than with the page. Each run also prints 500+ mentions found since the last review; mention extraction or the review count may be involved, but I have not profiled it.
Expected
The per-page write cost stays roughly constant, so a full backfill of a large chat is limited by Telegram's rate rather than by local processing.
The measurements helped a lot. Every page goes through one local save in our store, and the per-page cost grows with the chat's size, so something in that save scales with what's already stored. The "database is locked" in other commands fits this too. While one long save runs, the store is busy for everyone else.
We're reproducing it now on a synthetic store of about the same size, to see exactly which step grows. I'll post what we find and the fix here. If you can, run one page with --trace on 0.134.0 again and attach the timings. That would help us compare.
Found it. Every saved message ran one UPDATE that read the whole chat, to link replies saved before their thread's root. No index covered that column, so the cost grew with the chat: a page of 100 took 78 ms at 10k stored messages and 919 ms at 90k. Now it runs once per page, 32 to 42 ms up to 60k (benchmark). Shorter saves should also mean fewer "database is locked" errors in other commands while a sync runs.
The fix is merged (WireCatLabs/cli-core#3333, #924) and ships with the next tg release. An index in the next store version keeps it flat after that. I'll post the version here when it's out.
Released in 0.136.0. Update with npm install -g @wirecat/tg-cli@latest. The first sync after the update builds a new index once, after that pages should stay fast as the store grows. If it still slows down for you, reopen this issue with the message count and the rate you see.
One thing I missed above, it applies to #916 too. 0.136.0 also moves the store to version 73, and after that only tools on cli-core 1.0 open it. If you use other WireCat CLIs, update them before you run tg 0.136.0. gcal, drive, yandex-disk, bitrix24 and wordpress are not on cli-core 1.0 yet, so if you need one of them today, stay on tg 0.135.0 for now. The migration writes a rollback copy before it changes anything.
Activity
leemour commentedon Nov 24, 2026
The measurements helped a lot. Every page goes through one local save in our store, and the per-page cost grows with the chat's size, so something in that save scales with what's already stored. The "database is locked" in other commands fits this too. While one long save runs, the store is busy for everyone else.
We're reproducing it now on a synthetic store of about the same size, to see exactly which step grows. I'll post what we find and the fix here. If you can, run one page with
--traceon 0.134.0 again and attach the timings. That would help us compare.fix(sync): link a thread's replies once per page, not once per message (
perf(store): a history sync slows as the chat grows, and the fix (#405)
chore(deps): build on cli-core 0.753.0, background sync keeps --full-…
lebedev-nikita commentedon Nov 25, 2026
0.134.0, same chat, no other
tgprocess running. The local store already held ~543k messages of this chat (wirecat.db~650 MB):leemour commentedon Nov 25, 2026
Found it. Every saved message ran one UPDATE that read the whole chat, to link replies saved before their thread's root. No index covered that column, so the cost grew with the chat: a page of 100 took 78 ms at 10k stored messages and 919 ms at 90k. Now it runs once per page, 32 to 42 ms up to 60k (benchmark). Shorter saves should also mean fewer "database is locked" errors in other commands while a sync runs.
The fix is merged (WireCatLabs/cli-core#3333, #924) and ships with the next tg release. An index in the next store version keeps it flat after that. I'll post the version here when it's out.
leemour commentedon Nov 25, 2026
Released in 0.136.0. Update with npm install -g @wirecat/tg-cli@latest. The first sync after the update builds a new index once, after that pages should stay fast as the store grows. If it still slows down for you, reopen this issue with the message count and the rate you see.
leemour commentedon Nov 25, 2026
One thing I missed above, it applies to #916 too. 0.136.0 also moves the store to version 73, and after that only tools on cli-core 1.0 open it. If you use other WireCat CLIs, update them before you run tg 0.136.0. gcal, drive, yandex-disk, bitrix24 and wordpress are not on cli-core 1.0 yet, so if you need one of them today, stay on tg 0.135.0 for now. The migration writes a rollback copy before it changes anything.