fix: resolve critical performance issues and UI hangs by optimizing polling and PSS collection

This commit is contained in:
2026-02-23 01:47:13 +01:00
parent e6c5adca5e
commit 9ff0855102
3 changed files with 112 additions and 74 deletions

View File

@@ -91,8 +91,8 @@ function App() {
const [history, setHistory] = useState<{ time: string; cpu: number }[]>([]);
const [report, setReport] = useState<ProfilingReport | null>(null);
// Initial report check
useEffect(() => {
// Check for initial report (from CLI args)
const checkInitialReport = async () => {
try {
const data = await invoke<ProfilingReport | null>('get_initial_report');
@@ -105,13 +105,23 @@ function App() {
}
};
checkInitialReport();
}, []);
// Stats Polling
useEffect(() => {
let timeoutId: number;
let isMounted = true;
const fetchStats = async () => {
if (view !== 'dashboard' && !stats?.is_recording) return;
try {
const isRecording = stats?.is_recording ?? false;
const data = await invoke<SystemStats>('get_system_stats', {
minimal: isRecording || view === 'report'
minimal: (stats?.is_recording || view === 'report')
});
if (!isMounted) return;
setStats(data);
const avgCpu = data.cpu_usage.reduce((a, b) => a + b, 0) / data.cpu_usage.length;
@@ -123,12 +133,18 @@ function App() {
});
} catch (e) {
console.error(e);
} finally {
if (isMounted) {
timeoutId = window.setTimeout(fetchStats, 1000);
}
}
};
fetchStats();
const interval = setInterval(fetchStats, 1000);
return () => clearInterval(interval);
return () => {
isMounted = false;
clearTimeout(timeoutId);
};
}, [view, stats?.is_recording]);
const toggleRecording = async () => {