chore: optimize metrics framework and codebase readability#140
Open
chore: optimize metrics framework and codebase readability#140
Conversation
Extract 6 custom hooks from App.tsx (1737 → 686 lines): - useInstanceManager: instance CRUD, SSH hosts, discovery - useSshConnection: SSH connect/reconnect, passphrase dialog, health self-healing - useInstancePersistence: persistence scope, instance token, config version - useChannelCache: channel nodes, Discord guild channels, loading/refresh - useAppLifecycle: app update, analytics, preload, legacy migration, error handlers - useWorkspaceTabs: tab management, instance selection, install-ready handler Also fixes TS type narrowing for resolveInstanceTransport return type.
trace_command and record_timing now use microseconds instead of milliseconds. This fixes 0ms readings for fast local commands. PerfSample.elapsed_ms renamed to elapsed_us. CI report updated to show µs units with proper limits.
- JS initial load: add ≤200KB gate - Command P50: add ≤50ms gate (measured in µs) - Command max: add ≤200ms informational limit - Code Readability: expand from 2 to 18 tracked files with per-file targets - Files >500 lines: gate at ≤28 (must not increase) - SSH remote perf: replace 'expected in Docker' with descriptive label - metrics.md: update baselines and targets to match current codebase
Contributor
📊 Test Coverage Report
Coverage measured by |
Contributor
📦 PR Build Artifacts
|
Contributor
📏 Metrics Gate ReportStatus: ✅ All gates passed Commit Size ❌
Bundle Size ✅
Perf Metrics E2E ✅
Command Perf (local) ✅
Local command timings
Command Perf (remote SSH) ✅
Remote command timings (via Docker SSH)
Home Page Render Probes (mock IPC 50ms, cache-first render) ✅
Code Readability
|
Contributor
📸 UI ScreenshotsCommit: Light Mode — Core Pages
Dark Mode
Responsive + Dialogs
|
…bar footer Extract three more modules from App.tsx (686 → 500 lines): - useNavItems.tsx: navigation item definitions with icons - AppDialogs.tsx: passphrase and SSH edit dialogs - SidebarFooter.tsx: profile sync status, SSH transfer speed, pending changes bar
The previous threshold of 100µs was set before the ms→µs migration, causing false positives on CI. Local commands like get_app_preferences can take 100ms+ due to CI scheduling jitter.
Measured → New Limit (was): - Command P50: 32µs → ≤1,000µs (was 50,000µs) - Command P95: 36µs → ≤5,000µs (was 100,000µs) - Command Max: 40µs → ≤50,000µs (was 200,000µs) - JS initial load: 166KB → ≤180KB (was 200KB) - JS bundle gzip: 288KB → ≤350KB (was 512KB) - RSS: 3.1MB → ≤20MB (was 80MB) - Home probes: 10ms → ≤200ms (was 500ms) - Models probe: 107ms → ≤300ms (was 500ms) - Settled: 10ms → ≤1,000ms (was 5,000ms)
…es mock 1. Readability: auto-scans all .ts/.tsx/.rs files >300 lines, auto-calculates targets (60% of current, floor 500), with manual overrides for key files. Covers entire codebase instead of 18 hand-picked files. 2. Home Probes: annotated as mock IPC (50ms latency) so the 10ms values are understood as render-only timing, not E2E with real API calls.
…→ 959) - profile-utils.ts: ProfileForm type, credential helpers (emptyForm, normalizeOauthProvider, inferCredentialSource, etc.) - AutocompleteField.tsx: standalone autocomplete input component
… (963 → 901) Moves duplicate install detection and post-install onboarding guidance event emission into a dedicated hook with self-contained refs.
The ~10ms probes for status/version/agents/settled correctly measure cache-first rendering: prewarmRemoteInstanceReadCache populates the read cache during instance activation (50ms mock IPC), and Home mounts after the cache is warm. This is the actual user experience — the cache layer is working as designed. models (110ms) still goes through IPC because listModelProfiles is not in the prewarm path.
…→ 876) Replace 3 repetitive emitDataLoadMetric blocks with a compact loop.
Moves schedule formatting, relative time, job filtering, and cron expression humanization into src/lib/cron-utils.ts.
Replaces duplicate emptyForm, normalizeOauthProvider, inferCredentialSource, providerSupportsOptionalApiKey, AutocompleteField with imports from profile-utils.ts and AutocompleteField.tsx.
Skip the first 2 get_instance_runtime_snapshot / config_snapshot IPC calls (which are prewarm calls from instance activation). This forces the Home page poll loop to make fresh IPC calls, measuring actual fetch + render time instead of cache-hit render time. Per Chen Yu's feedback: probe values should reflect real IPC latency.
Also skip get_status_extra, get_status_light, list_agents_overview during the first 2 IPC rounds, so prewarm doesn't populate any cache.
Each run now clears localStorage before goto to prevent persisted cache from previous runs. Increased cold-start skip from 2 to 4 to handle all prewarm paths.
Skip=4 caused the poll loop to keep getting null from cache, preventing settled from firing. Skip=1 blocks just the prewarm call; the poll loop's 2nd call returns real data.
…863 → 5709) Moves skip_json5_ws_and_comments, scan_json5_string_end, scan_json5_value_end, extract_json5_top_level_value into src/json5_extract.rs. These are pure string parsers with no doctor-specific dependencies.
Moves 22 SSH-related type definitions to src/lib/ssh-types.ts. Re-exported from types.ts for backward compatibility — no import path changes needed in consuming files.
Extract 47 type definitions into 3 domain files: - ssh-types.ts (22 types, 160 lines) - rescue-types.ts (15 types, 142 lines) - install-types.ts (12 types, 82 lines) - cron-types.ts (10 types, 62 lines) All re-exported from types.ts for backward compatibility.
… → 5635) Moves DoctorTempGatewaySessionRecord/Store structs and 5 CRUD functions into src-tauri/src/doctor_temp_store.rs (80 lines). Registered in lib.rs, all call sites updated.
…rget) Moves 9 doctor/diagnosis type definitions to src/lib/doctor-types.ts. types.ts now passes readability gate (491 ≤ 500).
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.

























What
Addresses 5 metrics issues identified in PR #139's report:
1. SSH Command Failures — improved reporting
Replace misleading
⚠️ expected in Dockerwith descriptiveℹ️ Docker (no gateway)label.2. Code Readability — App.tsx refactored
Extract 6 custom hooks from App.tsx (1737 → 686 lines):
useInstanceManager— instance CRUD, SSH hosts, discoveryuseSshConnection— SSH connect/reconnect, passphrase, healthuseInstancePersistence— persistence scope, instance tokenuseChannelCache— channel data loading/cachinguseAppLifecycle— update check, analytics, preload, migrationuseWorkspaceTabs— tab management, instance selection3. Missing limits — gates added
4. Inaccurate measurements — microsecond precision
Switch
trace_command,record_timing, and timing macros from milliseconds to microseconds. Fast local commands now show actual timing instead of 0ms.5. Code Readability coverage — expanded
Track 18 files (up from 2) with per-file targets:
doctor_assistant.rs≤3000,rescue.rs≤2000,profiles.rs≤1500, etc.Commits
refactor:Extract App.tsx hooksfix:Switch to microsecond measurementfeat:Expand metrics limits and readability tracking