perf: eliminate per-query disk I/O and unblock result display from me…#216
Open
thomaswasle wants to merge 1 commit into
Open
perf: eliminate per-query disk I/O and unblock result display from me…#216thomaswasle wants to merge 1 commit into
thomaswasle wants to merge 1 commit into
Conversation
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.
Problem
Two independent issues were adding latency to every query execution:
find_connection_by_id — called for every query, export, explain, schema command, etc. — unconditionally read and
parsed the entire connections JSON file from disk using blocking std::fs::read_to_string on a Tokio worker thread.
On SSH connections, expand_ssh_connection_params triggered a second file read for the SSH config. This happened even
when the connection hadn't changed.
After each query completed, runQuery awaited fetchPkColumn — which fires parallel get_columns + get_foreign_keys
backend calls — before calling updateTab with the query result. The result grid was invisible until both metadata
requests finished. On a remote database, those two information_schema round-trips could add 100–500 ms of perceived
query latency.
Changes
src-tauri/src/connection_cache.rs (new)
Introduces ConnectionCache: a Mutex<Option<HashMap<String, SavedConnection>>> registered as Tauri state. Exposes
three operations:
src-tauri/src/commands.rs
miss reads the file once and warms the cache for all subsequent calls.
afterwards, so stale data is never served. Replaces all 12 call sites.
src/pages/Editor.tsx
Reorders the post-query flow so updateTab with the result fires immediately after the query returns. fetchPkColumn
is then started without await — it updates pkColumn, columnMetadata, and foreignKeys in the background via its own
updateTab call. Both updates target independent tab keys, so the React functional state updater merges them
correctly without races.
Notes
infrequently; the simplicity is worth it.
removing the await does not affect error handling.