Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Reapply "fix(webview): reduce CPU usage on Windows"

Louis Beaumontf760cda8b1f9
diff --git a/apps/screenpipe-app-tauri/app/shortcut-reminder/screen-matrix.tsx b/apps/screenpipe-app-tauri/app/shortcut-reminder/screen-matrix.tsx
index 40e418294..3a88d8a22 100644
--- a/apps/screenpipe-app-tauri/app/shortcut-reminder/screen-matrix.tsx
+++ b/apps/screenpipe-app-tauri/app/shortcut-reminder/screen-matrix.tsx
@@ -57,7 +57,11 @@ export function ScreenMatrix({
canvas.height = CANVAS_H * dpr;
ctx.scale(dpr, dpr);
+ let stopped = false;
+
const draw = () => {
+ if (stopped) return;
+
ctx.clearRect(0, 0, canvasW, CANVAS_H);
const isActive = activeRef.current;
@@ -101,10 +105,24 @@ export function ScreenMatrix({
rafRef.current = requestAnimationFrame(draw);
};
- rafRef.current = requestAnimationFrame(draw);
+ // Only run RAF when the tab is visible
+ const onVisibilityChange = () => {
+ if (document.hidden) {
+ cancelAnimationFrame(rafRef.current);
+ } else if (!stopped) {
+ rafRef.current = requestAnimationFrame(draw);
+ }
+ };
+ document.addEventListener("visibilitychange", onVisibilityChange);
+
+ if (!document.hidden) {
+ rafRef.current = requestAnimationFrame(draw);
+ }
return () => {
+ stopped = true;
cancelAnimationFrame(rafRef.current);
+ document.removeEventListener("visibilitychange", onVisibilityChange);
};
}, []);
diff --git a/apps/screenpipe-app-tauri/components/onboarding/particle-stream.tsx b/apps/screenpipe-app-tauri/components/onboarding/particle-stream.tsx
index b2e961a04..4b9e15066 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/particle-stream.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/particle-stream.tsx
@@ -233,7 +233,20 @@ export function ParticleStream({
const cx = width / 2, cy = height * 0.42;
+ let stopped = false;
+
+ const onVisibilityChange = () => {
+ if (document.hidden) {
+ cancelAnimationFrame(animRef.current);
+ } else if (!stopped) {
+ animRef.current = requestAnimationFrame(draw);
+ }
+ };
+ document.addEventListener("visibilitychange", onVisibilityChange);
+
function draw() {
+ if (stopped) return;
+
const p = progressRef.current;
const f = ++frameRef.current;
const s = state;
@@ -538,8 +551,14 @@ export function ParticleStream({
}
const w = width, h = height; // closure
- draw();
- return () => cancelAnimationFrame(animRef.current);
+ if (!document.hidden) {
+ animRef.current = requestAnimationFrame(draw);
+ }
+ return () => {
+ stopped = true;
+ cancelAnimationFrame(animRef.current);
+ document.removeEventListener("visibilitychange", onVisibilityChange);
+ };
}, [width, height]);
return (
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-health-check.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-health-check.tsx
index 496844ba3..1e010936c 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-health-check.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-health-check.tsx
@@ -169,7 +169,7 @@ export function useHealthCheck() {
// Start retry interval if not already running
if (!retryIntervalRef.current) {
- retryIntervalRef.current = setInterval(fetchHealth, 3000);
+ retryIntervalRef.current = setInterval(fetchHealth, 10000);
}
};
@@ -201,7 +201,7 @@ export function useHealthCheck() {
// Only start retry if this wasn't a manual close
if (!retryIntervalRef.current && event.code !== 1000) {
- retryIntervalRef.current = setInterval(fetchHealth, 3000);
+ retryIntervalRef.current = setInterval(fetchHealth, 10000);
}
};
} catch (error) {
@@ -217,7 +217,7 @@ export function useHealthCheck() {
}
if (!retryIntervalRef.current) {
- retryIntervalRef.current = setInterval(fetchHealth, 3000);
+ retryIntervalRef.current = setInterval(fetchHealth, 10000);
}
}
}, [setServerDown]); // stable deps — no cycle
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
index bb9d829fa..57faf9104 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
@@ -12,7 +12,7 @@ import { saveFramesToCache, loadCachedFrames } from "./use-timeline-cache";
let frameBuffer: StreamTimeSeriesResponse[] = [];
let flushTimer: ReturnType<typeof setTimeout> | null = null;
let progressUpdateTimer: ReturnType<typeof setTimeout> | null = null;
-const FLUSH_INTERVAL_MS = 150; // Flush every 150ms for smooth progressive loading
+const FLUSH_INTERVAL_MS = 500; // Flush every 500ms to reduce CPU usage
const PROGRESS_UPDATE_INTERVAL_MS = 500; // Only update progress indicator every 500ms to prevent flickering
// Connection retry logic - don't show error immediately, server might be starting