Repository navigation
feat(gc): add "bit gc" to remove unneeded objects from the local scope - #10714
Conversation
PR Summary by QodoAdd workspace garbage collection with safe object retention
AI Description
Diagram
High-Level Assessment
Files changed (19)
|
Code Review by Qodo
1. Concurrent imports can lose objects
|
…ot set the scope layer no longer refers to workspaces - it is handed the ids to keep. also keeps stashed snaps, refuses to delete from a partial object inventory, and keeps unexported local-lane ancestry.
|
Code review by qodo was updated up to the latest commit 99e0e08 |
|
Code review by qodo was updated up to the latest commit e5a669c |
|
Code review by qodo was updated up to the latest commit 4080e13 |
|
Code review by qodo was updated up to the latest commit 454dfa6 |
…core aspect both commands prune local state, and clear-cache already reaches the scope and the consumer lazily, so no workspace/scope aspect dependencies are added to it.
|
Code review by qodo was updated up to the latest commit 856176d |
… restore and size reporting the header-only read was never reached: the scope aspect installs onPostObjectRead whether or not a transformer is registered, so every run inflated every object. ~27% less cpu on a 254 MB scope. also: a stash that parses but has no stashCompsData no longer reads as empty, the backup directory is emptied once restored, and stray temp files count towards the size freed.
|
Code review by qodo was updated up to the latest commit 9ef5f37 |
…rom acting a lane in the trash still names its snaps and can be brought back, and a detached head's unexported parents are reachable from nowhere else - both are roots now, as they already were in the collector for bare scopes. also: --dry-run no longer performs a --restore, --dry-run --backup no longer previews disk savings a real backup run wouldn't make, and a temp file is only removed once it is old enough not to be a write in progress.
|
Code review by qodo was updated up to the latest commit 2bff1d0 |
… progress an import writes a Version and its Sources before pointing the ModelComponent at them. a run that reads the components in between sees objects nothing refers to yet. anything written in the last few minutes is now left for the next run. this narrows the window rather than closing it - only a scope-wide lock held across every object write would do that, and there is none today.
|
Code review by qodo was updated up to the latest commit aaa855d |
…om the checkout - a lane's readme is pointed at separately from its components, so it needed its own root - an env reached through "extensions" is rooted after the first dependency pass, so that pass now repeats until it stops adding roots - otherwise the env is kept while what it depends on is not - --keep-versions counts back from where the workspace is checked out rather than from the head; the head is kept because it is a head, so starting there too would just double what N means - versions are removed before the files they point at, in two passes, since each pass is concurrent and nothing here is transactional
|
Code review by qodo was updated up to the latest commit d614de5 |
refsWithOptions doesn't report it, and the diverge calculation loads it before it can tell the two sides are unrelated, so it has to be here. also decide a remote-lane file by whether it reads as one rather than by its name: a lane is allowed to be called .DS_Store, and skipping it by name would delete the head it holds.
|
Code review by qodo was updated up to the latest commit 5c915a8 |
…he stat walks both sit inside the scope and gc frees neither, so leaving them out reported a scope smaller than the disk. they get a line of their own rather than silently swelling the total. the directory-size walks now go through pMapPool like everything else here - a backup or a trash can hold as many files as the scope itself.
|
Code review by qodo was updated up to the latest commit 5c17b2e |
restore emptied the directory in place, so objects a concurrent --backup moved there mid-restore were removed from the backup without ever being brought back. the directory is renamed first - atomic within the scope - leaving a concurrent run to write into a fresh one it can keep. a restore interrupted after the rename leaves a directory nothing would look for again, so those are picked up on the next restore.
|
Code review by qodo was updated up to the latest commit 2e9db9f |
…dirs "bit lane checkout-history" and "revert-history" hand checkout the exact versions written in a history entry. a version that has since left the lane is reachable from nothing else, and on a lane that was never exported it is here and nowhere else, so every entry's versions are roots now. restore also claims each staging directory by renaming it again before copying, so two restores at once can't both read a directory one of them is removing.
|
Code review by qodo was updated up to the latest commit f06f296 |
the tip was rooted on its own and its chain left to the deletion pass, which is the wrong half to keep for a lane that was never exported. it goes through the same bare-hash walk as staged snaps and stashes, stopping where the remote has it.
|
Code review by qodo was updated up to the latest commit f2355b4 |
|
Code review by qodo was updated up to the latest commit b942c64 |
….list (#10730) `Repository.list(types)` read and inflated every object file in the scope just to check its type, then discarded almost all of them — most of a scope is file contents, which no caller of `list()` asks for. It now reads the type from the header in the first 512 bytes (the mechanism `bit gc` added in #10714) and only reads the full file when the type matches. This speeds up every `list()` caller: rebuilding a missing `index.json` (on scope load, and after every `bit clear-cache`), `bit cat-scope`, the bare-scope garbage collector, `toObjectList` and the doctor's orphan-symlink check. On a 254 MB scope (27k objects) the index rebuild went from ~3.1s to ~1.4s; the full read scales with the scope's bytes and the header read with its object count, so the gap grows on larger scopes. When a content transformer is registered the header can't be read on its own, so that case keeps the single full read. An object of an unregistered type is still skipped rather than thrown on, as before.
A workspace keeps all versions of all components that it imports. Each new version adds its source files, and nothing removes the superseded ones. The local scope thus grows to many gigabytes.
bit gcremoves the versions that nothing refers to. It keeps the checked-out version of each component, all heads (of the workspace, of its lanes and of the tracked remotes), all local snaps that you did not export yet, and the dependencies of these. Bit fetches a removed version again from the remote when it needs it.The command removes a version as a unit: the Version object and its Source objects together.
sources.get()reads only the Version object to decide if a version is local. A Version object without its files thus makes the importer skip the fetch, and the command fails later.--keep-versions <n>keeps the last n versions of each workspace component. The recent history stays local forbit logandbit blame.In a bare scope the command runs the existing collector that keeps all history, because a bare scope is the source of truth and not a cache.
On this repository: 5.3 GB to 254 MB in 45 seconds, or 364 MB with
--keep-versions 5.Other options:
--dry-run,--backup,--restore,--verbose,--json. 11 unit tests cover the collector.