Skip to content

perf(comments): join docs over a small socket pool in listComments - #60

Merged
aloth merged 1 commit into
aloth:mainfrom
fredericosantos:perf/parallel-comments
Oct 15, 2026
Merged

aloth merged 1 commit into
aloth:mainfrom
fredericosantos:perf/parallel-comments

Conversation

@fredericosantos

Copy link
Copy Markdown
Contributor

olcli comments list joins every doc in the project one at a time (about 0.25 s each), so a 43-doc project takes around 14 s. resolve, reopen and delete look the thread up first, so they pay the same cost.

Why not just join in parallel on the one socket

I tried. The socket is Socket.IO 0.9 over xhr-polling, and socketRpc hands the acknowledgment to whichever request polls first, so concurrent calls on a shared socket steal each other's acks. Five concurrent joinDoc calls timed out after 7 s.

Change

listComments now spreads the docs over a small pool of sockets (up to 4), each pulling the next doc from a shared index. The parsing loop is unchanged. The diff looks bigger than it is because the old try/finally is gone and the loop is de-indented; git diff -w is about 40 lines in src/client.ts. CHANGELOG entry included.

Numbers

One bench project (43 docs, 27 threads, 8 with replies, 3 resolved), median of 5 runs:

command before after
comments list 14.1 s 5.5 s
comments resolve 14.6 s 2.1 s
comments reopen 14.6 s 5.4 s

The "after" numbers are bimodal (about 2 s or about 5 s) and I don't know why; it looks like network or server variance. Output is identical before and after (same 27 threads).

Tests

npm test goes from 87 to 88 passing. The new test stubs joinDocument, openProjectSocket and closeProjectSocket on a client instance (no network), and asserts 2 to 4 sockets are used, every socket is closed, and the comments come back right. It fails on the old code.

What I haven't verified

  • The pool size of 4 is my pick. 4 and 8 sockets both worked for me, but I don't know Overleaf's limit for concurrent sockets per user, and it isn't configurable here.
  • One account and one project only.
  • The history-ot doc path is untouched but untested against a live server (my docs are all sharejs-text-ot).
  • All joined docs are held in memory at once.

CONTRIBUTING says to discuss bigger changes first. Happy to open an issue and move the discussion there if you'd rather.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
aloth added a commit that referenced this pull request Oct 15, 2026
Speeds up the comment commands by fetching docs over a small socket pool (#60), stops the pool cleanly on failure, falls back to fewer sockets on HTTP 429, and adds --concurrency and OLCLI_CONCURRENCY.
@aloth
aloth merged commit 6160cbd into aloth:main Oct 15, 2026
@aloth

aloth commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, shipped in v0.14.0. On a 23-doc project comments list went from about 7 s to 3 s, with identical output.

Two follow-ups in the same release: a failed join now stops the pool and closes all sockets before the error is reported, and the pool size is configurable via --concurrency <n> or OLCLI_CONCURRENCY (1-8, default 4). history-ot is still untested live.

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