perf: reduce plugin and memory startup overhead

This commit is contained in:
Peter Steinberger
2026-03-22 02:03:23 +00:00
parent 1ad3893b39
commit 2cc777539a
3 changed files with 42 additions and 67 deletions

View File

@@ -94,6 +94,12 @@ function shouldIgnoreMemoryWatchPath(watchPath: string): boolean {
return parts.some((segment) => IGNORED_MEMORY_WATCH_DIR_NAMES.has(segment));
}
export function runDetachedMemorySync(sync: () => Promise<void>, reason: "interval" | "watch") {
void sync().catch((err) => {
log.warn(`memory sync failed (${reason}): ${String(err)}`);
});
}
export abstract class MemoryManagerSyncOps {
protected abstract readonly cfg: OpenClawConfig;
protected abstract readonly agentId: string;
@@ -650,9 +656,7 @@ export abstract class MemoryManagerSyncOps {
}
const ms = minutes * 60 * 1000;
this.intervalTimer = setInterval(() => {
void this.sync({ reason: "interval" }).catch((err) => {
log.warn(`memory sync failed (interval): ${String(err)}`);
});
runDetachedMemorySync(() => this.sync({ reason: "interval" }), "interval");
}, ms);
}
@@ -665,9 +669,7 @@ export abstract class MemoryManagerSyncOps {
}
this.watchTimer = setTimeout(() => {
this.watchTimer = null;
void this.sync({ reason: "watch" }).catch((err) => {
log.warn(`memory sync failed (watch): ${String(err)}`);
});
runDetachedMemorySync(() => this.sync({ reason: "watch" }), "watch");
}, this.settings.sync.watchDebounceMs);
}