Optimize phone CPU usage

This commit is contained in:
James Babcock committed 2026-09-27 23:16:41 -07:00
1 parent 449cb0bf73
commit 45d2ece0d2
19 files changed
+485 -103

No files matched your search

+7 -3
View File
@@ -14,8 +14,9 @@ export type PersistedOpenApps = {
const STATE_VERSION = 1;
const FILE_NAME = "open-apps.json";
// Coalesces bursts (restore, sidebar scrolling) into one write; short enough
// that a build-reinstall kill right after a change rarely loses it.
// Coalesces bursts (restore, sidebar scrolling) into one write once they
// settle; short enough that a build-reinstall kill right after a change
// rarely loses it.
const WRITE_DELAY_MS = 1000;
function openAppsFilePath(): string {
@@ -50,7 +51,10 @@ let pendingState: PersistedOpenApps | null = null;
/** Save the open-app state (debounced; the latest state wins). */
export function savePersistedOpenApps(state: PersistedOpenApps): void {
pendingState = state;
if (writeTimer !== null) return;
// Restarted on every change: scrolling through the switcher changes the
// foreground app a few times a second, and each synchronous write costs
// several milliseconds of main thread.
if (writeTimer !== null) clearTimeout(writeTimer);
writeTimer = setTimeout(() => {
writeTimer = null;
const state = pendingState;