CommunityCoding & Developmentgithub.com

soku-perf

>- Use when optimizing startup latency, UI responsiveness, or slow I/O / search performance in desktop (WebView2/Tauri/Electron), web SPA, or CLI/backend apps while guaranteeing zero functional regressions. Enforces phase-split millisecond profiling, forced-reflow elimination, immutable asset caching, OS IPC offloading, adaptive (mtime, len) I/O caching, and multi-run statistical + E2E regression gates.

What is soku-perf?

soku-perf is a Claude Code agent skill that >- Use when optimizing startup latency, UI responsiveness, or slow I/O / search performance in desktop (WebView2/Tauri/Electron), web SPA, or CLI/backend apps while guaranteeing zero functional regressions. Enforces phase-split millisecond profiling, forced-reflow elimination, immutable asset caching, OS IPC offloading, adaptive (mtime, len) I/O caching, and multi-run statistical + E2E regression gates.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/youshinh/soku-perf/tree/HEAD

Installed? Explore more Coding & Development skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

soku-perf — Zero-Regression, Profile-First Performance Tuning

Never optimize by guesswork. Follow this 4-phase loop until the target latency (e.g., sub-300 ms warm boot, <1 ms warm search) is reached with 0 functional regressions.


Phase 1: Phase-Split Millisecond Profiling (Measure First)

Never rely on a single wall-clock total. Instrument the critical path into 5–8 monotonic timestamps (e.g., process_start -> window_shown -> runtime_env -> controller_ready -> html_req -> js_req -> js_exec_start -> init_start -> app_ready) and capture 1 cold + 3–5 warm runs:

  • Compute Cold, Warm Median, and Warm Min; compare against project baseline history.
  • Always target the single largest delta interval first.
  • If a single function (e.g., initApp()) takes >10 ms, bisect it with temporary sub-phase markers (cfg_done, sess_done, tab_done) before touching any code, then remove temporary markers once fixed.

Phase 2: 6 High-Leverage Optimization Patterns (Low-Risk First)

Apply in order of impact-to-risk ratio:

P1. Eliminate Boot-Time Forced Synchronous Layouts (Highest UI ROI)

During initial boot (bootInitializing = true until app_ready), audit and defer any call that forces browser style/layout recalculation:

  • el.focus(), el.selectionStart = ..., el.setSelectionRange(...)
  • el.offsetWidth, el.clientWidth, el.scrollHeight, el.getBoundingClientRect(), getComputedStyle(el)
  • Fix: Keep a single focusEditorAtEnd() right after app_ready, and defer secondary measurements (scrollbar probes, tab overflow checks, gutter/status-bar redraws) to the next requestAnimationFrame.

P2. Split Non-Critical CSS/JS & Enable immutable Caching

  • Move hidden-at-boot CSS (modals.css, panels.css, print.css) and non-critical JS modules into deferred bundles loaded after app_ready.
  • Serve content-hashed boot CSS/JS (?v=<hash>) with Cache-Control: public, max-age=31536000, immutable so browser HTTP cache and V8 Code Cache eliminate re-parse cost on warm starts.
  • Add <link rel="preload" as="style|script"> at the top of <head> for parallel fetching.

P3. Overlap Idle Wait Time & Offload Synchronous OS IPC

  • While waiting for heavy runtime initialization (e.g., WebView2/Chromium controller startup ~200 ms), run independent work in parallel on background threads:
    • Pre-decompress embedded gzip boot assets into an RwLock<HashMap<_, Arc<Vec<u8>>>> (zero-copy Arc return, no .clone()).
    • Pre-spawn worker thread pools (RPC / I/O workers).
  • Offload blocking OS shell IPC (e.g., Win32 Shell_NotifyIconW tray icon registration) to a background thread so Explorer IPC never stalls UI-thread resource callbacks.

P4. Adaptive (mtime, len) In-Memory Cache for Slow / Cloud I/O

For file search/scan on potentially slow mounts (Google Drive, OneDrive, SMB):

  • Maintain an in-memory HashMap<PathBuf, DirCache> storing pre-lowercased text and extracted metadata.
  • Track all scanned directory mtimes (dir_mtimes). Apply a short scan TTL (e.g., 3 s) only when the previous scan was slow (>= 25 ms); on fast local SSDs, check (mtime_ns, len) every time and only re-read modified files in parallel.
  • Immediately invalidate the cache on every write path (saveFile, saveFileAs, createNote, append_entry).

P5. Isolated A/B Test Before Changing Runtime Flags

  • Test flags (e.g., --in-process-gpu, --disable-extensions) in isolation (config/env only, 3–5 runs) before changing code or default contracts.
  • Drop any flag that shows no statistically clear win.

P6. Audit Top-Level DOM Refs Before Lazy-Mounting Large HTML

  • Before moving large hidden modals into <template> or deferred HTML fragments, run a static audit counting top-level document.getElementById(...) references to inner IDs.
  • If dozens of top-level refs exist, exhaust P1–P4 first; only refactor DOM mounting when P1–P4 are already saturated and a dedicated lazy-ref design is justified.

Phase 3: Multi-Run Statistical Verification

  • Re-run the exact same benchmark harness (1 cold + 3–5 warm runs) after each change.
  • Verify both internal trace (app_ready) and end-to-end harness (warmAppReadyMedianMs, coldAppReadyMs, reattachWakeMs, memory/RSS, binary size).
  • Keep a change only if it measurably improves or holds latency with zero instability.

Phase 4: Zero-Regression Gate (Mandatory)

Speed optimizations must never drop features, weaken security, or silently break default config contracts:

  1. Run real-browser / runtime E2E tests (DOM/SVG rendering, focus/keyboard, modals, settings, zero Uncaught console errors).
  2. Run full unit & static contract test suites.
  3. Rebuild release artifacts and confirm clean git diff (no leftover temporary profiling markers).

Related Skills