fix: resolve critical performance issues and UI hangs by optimizing polling and PSS collection
This commit is contained in:
26
src/App.tsx
26
src/App.tsx
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user