perf(canvas): reuse immutable recovery encoding subtrees

This commit is contained in:
2026-11-08 16:42:40 +08:00
parent ff07b52a21
commit 8a58d9785c
5 changed files with 107 additions and 5 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
import { isSealedRecoveryImage } from './recovery-encoding.ts';
import type { Json } from '../canvas-core/types.ts';
import { clone, equal, fault, validJson } from '../canvas-core/values.ts';
@@ -117,7 +118,7 @@ export function createBrowserStorage(options: { indexedDB?: IDBFactory; locks?:
},
async commit(leader: StorageLeader, batch: DurableBatch) {
// Copy before awaiting: callers cannot change the durable cut while a transaction queues.
const image = clone(batch.image), files = [...(batch.files ?? [])]; validateImage(image);
const image = isSealedRecoveryImage(batch.image) ? batch.image : clone(batch.image), files = (batch.files ?? []).map(file => ({id:file.id,bytes:file.bytes})); if(!isSealedRecoveryImage(image))validateImage(image);
const stored: StoredImage = { image, checksum: await checksum(image) };
return execute(leader, ['checkpoints', 'journal', 'files'], 'readwrite', async (transaction, metadata, key) => {
const previous = metadata.throughRevision;