Skip to content

Add garbage collection to SyncOPFSFileSystem to prevent unbounded disk growth#4

Open
MillanWangGadget wants to merge 1 commit into
mainfrom
mill/garbageCollector
Open

Add garbage collection to SyncOPFSFileSystem to prevent unbounded disk growth#4
MillanWangGadget wants to merge 1 commit into
mainfrom
mill/garbageCollector

Conversation

@MillanWangGadget

Copy link
Copy Markdown

Summary

  • Problem: SyncOPFSFileSystem's arena file only ever grew — overwriting
    or deleting files freed pages internally but never truncated the backing OPFS
    file, causing unbounded disk usage in long-lived sessions.
  • Automatic reclamation: After every file overwrite/delete, trailing free
    pages at the end of the arena are now truncated immediately (with a 1 MiB
    floor to avoid thrashing).
  • Manual compaction: New gc() method relocates all live file data
    contiguously and truncates, eliminating internal fragmentation.
  • Observability: New getStats() returns arenaBytes, allocatedBytes,
    freeBytes, and freeFragments for monitoring.

…k growth

      The arena file previously only grew and never shrank. When files were
      overwritten or deleted, old pages were added to the free list but the
      underlying OPFS file retained its full size, causing massive disk usage
      over time.

      - Auto-reclaim trailing free pages after every free (shrinkArenaTrailingFreeSpace)
      - Add gc() for full compaction/defragmentation
      - Add getStats() for monitoring arena usage
      - Add tests proving sequential edits don't grow storage disproportionately
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant