perf: parse chat history off the main thread on tab open - #18
Merged
Conversation
The remaining tab-open stall was the synchronous parse of the persisted chat history (a multi-megabyte JSON via serde) inside `Workspace::new`, on the GTK main thread. Now the history starts empty and is parsed on a worker thread; a short poll delivers the parsed messages back to the UI thread and hands them to the panel's new `load_history` callback, which populates the shared buffer and renders the first page in idle-chunked batches (as before). The autosave dirty counter is seeded to the loaded length so the first autosave doesn't rewrite what we just read. `create_agent_panel` no longer reads history at construction; it returns a `load_history` hydration callback instead.
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.
Symptom
After the instant-switch fix (#17), the residual tab-open pause (~half a second) was the synchronous parse of the persisted chat history — a multi-MB JSON via serde — running inside
Workspace::newon the GTK main thread.Fix
Vec<ChatMessage>back to the UI thread.create_agent_panelno longer reads history at construction. It returns a newload_historycallback; the parse-completion handler calls it to populate the shared buffer and render the first page in the existing idle-chunked batches.last_saved_chat_len, now a sharedRc<Cell<usize>>) is seeded to the loaded length, so the first autosave doesn't redundantly rewrite the history we just read.Net: building a tab no longer blocks on the JSON parse — the panel appears immediately and history streams in once parsed.
Testing
cargo clippy --lib --bins -- -D warnings— cleancargo fmt --check— cleancargo test— all pass