Repository navigation
perf(rpc): answer requests on the blocking pool; slow reads aside - #81
Merged
Merged
Conversation
Each request ran inline in the connection loop, on a runtime thread: a files.list walk over a large work folder held both that thread and every notification behind it. Requests now run on the blocking pool. They still answer in order and before the notifications after them, since the app stores a whole Bot or Routine from an answer and takes it as newer than what came before. Reads the app never sets against notifications (files, screens, attachments, token usage) answer on their own, so they hold back no live text. Notifications are written straight to text, without building a Value first.
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.
Second performance round, slice 2.
What
The connection loop answered each request inline, on a tokio worker. A slow request held that worker and every notification for the connection until it finished. Examples:
files.listwalking a large work folder, which runs every 4 s while a bot works with the files panel open;files.readreading a 20 MB file;Now (
rpc/mod.rs):spawn_blocking), so they never hold a runtime thread.putBot,withRoutine, the bulk loads insync.ts) and treats an answer as newer than everything received before it. A first version answered everything out of order; a review of the app showed that would let a latebots.restartorbots.setPausedanswer overwrite a newerbot.state. So the order is kept.files.list,files.read,screens.list,attachments.readandusage.tokens. They answer when ready, and live text keeps flowing meanwhile.Serializewrapper, instead ofto_value, thenjson!, thento_string. Browser frames get the same treatment.The spec (11.1) describes the order rule. It also fixes the outdated lag limit (1024 → 4096, which #75 changed).
Tests
New
tests/rpc_queue.rs, which holds the store on another thread for 1 s:files.listwaits, and the live text goes out first;crews.listwaits, and its answer still goes out before the text;The first test fails on
main; I checked that by running it against the oldrpc/. The full suite, clippy and fmt pass.While writing these tests I also saw that a worker blocked on the store mutex stalls tokio's timers. The 40 ms live-text flush waited for the whole hold. That is the case for moving the store to its own thread, which is noted for later.
Manual check (real Claude)
With the dev daemon and a crew whose work folder is large (for example a folder with
node_modules-free source trees of a few thousand files), open the files panel while a bot writes a long answer. The text should stream smoothly, without pauses every 4 s.