performance improvements

This commit is contained in:
vcoppe committed 2026-10-18 10:50:34 +02:00
1 parent 9033401094
commit 48325e6016
5 files changed
+107 -120

No files matched your search

+23 -16
View File
@@ -976,15 +976,30 @@ class Engine {
* rely on the order, the files and the selection being consistent when they are notified.
*/
private async sync(backend: Backend, update: Outcome) {
const [[canUndo, canRedo, canPaste], clipboard, selection, order] = await Promise.all([
const filesChanged =
update.added.length + update.modified.length + update.removed.length > 0;
// the statistics depend on the selection, on its order, and on the files
const statisticsChanged = update.selectionChanged || update.orderChanged || filesChanged;
// read in parallel: with the engine in another process (desktop app), each read is a
// round trip
const files = get(this._files);
const [
[canUndo, canRedo, canPaste],
clipboard,
selection,
order,
workspace,
setStatistics,
added,
modified,
] = await Promise.all([
Promise.all([backend.can_undo(), backend.can_redo(), backend.can_paste()]),
update.clipboardChanged ? backend.clipboard() : undefined,
update.selectionChanged ? backend.selection() : undefined,
update.orderChanged ? backend.file_order() : undefined,
]);
const files = get(this._files);
const [added, modified] = await Promise.all([
filesChanged ? backend.desktop?.workspace() : undefined,
statisticsChanged ? this._statistics.refresh(backend) : undefined,
Promise.all(
update.added.map((id) => readFileState(backend, id, this._colors, this._visibility))
),
@@ -1036,18 +1051,10 @@ class Engine {
}
});
if (update.added.length + update.modified.length + update.removed.length > 0) {
await this.refreshWorkspace(backend);
}
// the statistics depend on the selection, on its order, and on the files
if (
update.selectionChanged ||
update.orderChanged ||
update.added.length + update.modified.length + update.removed.length > 0
) {
await this._statistics.refresh(backend);
if (workspace) {
this._workspace.set(workspace);
}
setStatistics?.();
}
}
+7 -3
View File
@@ -29,10 +29,14 @@ export class StatisticsReader {
/** @param enqueue Does a task after the calls to the engine that were made before it. */
constructor(private enqueue: <T>(task: () => Promise<T>) => Promise<T>) {}
/** Reads the statistics of the selection again, after it or the files changed. */
async refresh(backend: Backend) {
/**
* Reads the statistics of the selection again, after it or the files changed. Resolves to what
* puts them in the store, for the caller to do it together with its other updates.
*/
async refresh(backend: Backend): Promise<() => void> {
this._backend = backend;
this._store.set(await this.read(backend));
const statistics = await this.read(backend);
return () => this._store.set(statistics);
}
/**