fix(cli): use subprocess IPC for non-blocking native calls

Closed
JU
1y ago
+145-9

Summary

Fixes the TUI loader freezing during data loading by running heavy native Rust functions in a subprocess.

Problem

The CLI TUI loader/spinner would freeze for 100-500ms while native Rust functions executed, blocking the Node.js event loop.

Solution

  • Add native-runner.ts: subprocess that reads method/args from stdin, executes native function, writes result to stdout
  • Add *NativeAsync() wrappers that spawn subprocess and communicate via stdin/stdout pipes
  • Update useData.ts to use async subprocess versions

Benefits over temp file approach

AspectTemp Filesstdin/stdout
File I/O2 writes + 2 readsNone
CleanupManual unlinkSyncAutomatic
Crash safetyLeftover filesClean
SecurityData on diskIn memory

Testing

The spinner now animates smoothly throughout the entire data loading process.