maxCachedTreeEntries property
How much tree _snapshots may hold, counted in entries across every
cached branch.
In entries rather than in snapshots, because snapshots differ by orders of magnitude: a bound of "eight branches" is meaningless for a repository with sixty thousand files and punishing for a workspace spanning twenty small ones. Counting the thing that actually consumes memory lets many small repositories coexist and caps one large one.
The floor on the number is eviction's cost rather than memory: a snapshot dropped and wanted again costs a commit read and a tree read, and a sync tick touches every open document's branch — so a budget smaller than the working set makes every tick pay for the last one's evictions. A hundred thousand entries holds a workspace of twenty repositories of five thousand files each without ever evicting a branch that is in use.
The ceiling is memory: an entry is a path, a sha, a mode and a size, so with the two strings it is a couple of hundred bytes, and the budget is something like twenty megabytes. That is a lot to hold and a little to cap — and capping it is the whole point, because the alternative is not a smaller cache but every tree the session ever read.
Neither bound is measured, because the deciding quantity is how large the user's repositories are. So the cache reports instead (diagnostics): every eviction, and separately the case that means the budget is too small — see thrashWindow. The budget does not adapt to what is reported. A cache sized by recent request history would be a second control loop inside the sync loop; this one says what happened and a person decides.
Implementation
int maxCachedTreeEntries = 100000;