Skip to content

Commit

Permalink
update compaction policy to avoid tiny-doc / single-big-change perfor…
Browse files Browse the repository at this point in the history
…mance problem
  • Loading branch information
pvh committed Dec 1, 2023
1 parent 95bdbf9 commit dd7495e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/automerge-repo/src/storage/StorageSubsystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ export class StorageSubsystem {
incrementalSize += chunk.size
}
}
return incrementalSize >= snapshotSize
// if the file is currently small, don't worry, just compact
// this might seem a bit arbitrary (1k is arbitrary) but is designed to ensure compaction
// for documents with only a single large change on top of an empty (or nearly empty) document
// for example: imported NPM modules, images, etc.
// if we have even more incrementals (so far) than the snapshot, compact
return snapshotSize < 1024 || incrementalSize >= snapshotSize
}
}

0 comments on commit dd7495e

Please sign in to comment.