Commit df7d6050e45f

Vincent Demeester <vincent@sbr.pm>
2026-03-24 13:23:40
perf: speed up pi startup with JITI_TRY_NATIVE
Set JITI_TRY_NATIVE=true to bypass jiti's babel transform and use Node.js native imports for pi extensions. Reduced startup from >30s to ~7s with all 41 extensions loaded. Fixed hanging extensions by adding unref() to dbus-monitor child process in auto-theme and setInterval in org-todos.
1 parent 44f8e66
Changed files (4)
dots
pi
agent
extensions
home
common
shell
pkgs
my
scripts
bin
dots/pi/agent/extensions/org-todos/index.ts
@@ -1414,10 +1414,12 @@ export default function (pi: ExtensionAPI) {
     updateTodayStatus(ctx);
     
     // Set up periodic updates every 5 minutes
+    // Use unref() so the interval doesn't prevent process exit
     const updateInterval = setInterval(() => {
       updateInboxStatus(ctx);
       updateTodayStatus(ctx);
     }, 5 * 60 * 1000); // 5 minutes in milliseconds
+    updateInterval.unref();
     
     // Clean up interval on session end
     (pi as any).on("session_end", async () => {
dots/pi/agent/extensions/auto-theme.ts
@@ -130,6 +130,11 @@ function startWatching(): void {
 	});
 
 	watchProcess = dbusMonitor;
+
+	// Unref the child process so it doesn't prevent Node.js from exiting
+	dbusMonitor.unref();
+	dbusMonitor.stdout?.unref();
+	dbusMonitor.stderr?.unref();
 }
 
 function stopWatching(): void {
home/common/shell/zsh.nix
@@ -61,6 +61,9 @@
     '';
     sessionVariables = {
       RPROMPT = "";
+      # Use Node.js native imports in jiti, bypassing babel transform.
+      # Dramatically reduces pi extension loading time (~10x faster startup).
+      JITI_TRY_NATIVE = "true";
     };
     # No plugins here — we use home.file to place them without auto-sourcing.
     # Sourcing is handled by dots/config/zsh/tools/*.zsh
pkgs/my/scripts/bin/pir
@@ -3,6 +3,10 @@
 # Usage: pir [args...]
 # Uses google-vertex-claude provider with claude-sonnet-4-6
 
+# Use Node.js native imports where possible, bypassing jiti's babel transform.
+# This dramatically reduces extension loading time (~10x faster startup).
+export JITI_TRY_NATIVE=true
+
 exec pass-run -q \
   -e GOOGLE_CLOUD_PROJECT=redhat/google/osp/project \
   -e GOOGLE_CLOUD_LOCATION=redhat/google/osp/location \