Release v1.4.15 with deep performance optimizations and crash prevention
- Convert session persistence to async during downloads (prevents 50-200ms UI freezes) - Avoid unnecessary Buffer.from() copy on Uint8Array chunks (zero-copy when possible) - Cache effective speed limit for 2s (eliminates Date object creation per chunk) - Replace O(n) speed event shift() with pointer-based pruning - Throttle speed event pruning to every 1.5s instead of per chunk - Optimize refreshPackageStatus to single-loop counting (was 4 separate filter passes) - Fix global stall watchdog race condition (re-check abort state before aborting) - Add coalescing for async session saves (prevents write storms) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
cc887eb8a1
commit
147269849d
@@ -1,4 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import fsp from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { AppSettings, BandwidthScheduleEntry, SessionState } from "../shared/types";
|
||||
import { defaultSettings } from "./constants";
|
||||
@@ -210,3 +211,30 @@ export function saveSession(paths: StoragePaths, session: SessionState): void {
|
||||
fs.writeFileSync(tempPath, payload, "utf8");
|
||||
fs.renameSync(tempPath, paths.sessionFile);
|
||||
}
|
||||
|
||||
let asyncSaveRunning = false;
|
||||
let asyncSaveQueued: { paths: StoragePaths; session: SessionState } | null = null;
|
||||
|
||||
export async function saveSessionAsync(paths: StoragePaths, session: SessionState): Promise<void> {
|
||||
if (asyncSaveRunning) {
|
||||
asyncSaveQueued = { paths, session };
|
||||
return;
|
||||
}
|
||||
asyncSaveRunning = true;
|
||||
try {
|
||||
await fs.promises.mkdir(paths.baseDir, { recursive: true });
|
||||
const payload = JSON.stringify({ ...session, updatedAt: Date.now() });
|
||||
const tempPath = `${paths.sessionFile}.tmp`;
|
||||
await fsp.writeFile(tempPath, payload, "utf8");
|
||||
await fsp.rename(tempPath, paths.sessionFile);
|
||||
} catch (error) {
|
||||
logger.error(`Async Session-Save fehlgeschlagen: ${String(error)}`);
|
||||
} finally {
|
||||
asyncSaveRunning = false;
|
||||
if (asyncSaveQueued) {
|
||||
const queued = asyncSaveQueued;
|
||||
asyncSaveQueued = null;
|
||||
void saveSessionAsync(queued.paths, queued.session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user