Repository navigation
perf(web): count a closed workspace's runs from counts kept on disk - #314
Merged
harenome merged 1 commit intoNov 23, 2026
Merged
Conversation
The Workspaces page counted each closed workspace by decoding every job cache with all its trials, after each start. A closed workspace whose jobs had all ended now keeps its runs and checks in jobs/counts.json, under a digest of the key the in-memory counts use (its roots, their heads, the run records' states), with the catalogue's signature added. A start reads that file instead of the trials while the key matches; the open workspace and one with a job still going are counted as before and never stored.
harenome
force-pushed
the
perf/workspace-counts-summary
branch
from
November 23, 2026 13:21
e4e9df3 to
1f50930
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #309
What
/workspacescounted each closed workspace by decoding every job cache with all its trials, then read only job-level fields._COUNTSkept the result in memory, so every start paid again. A closed workspace whose jobs had all ended now also keeps its runs and checks injobs/counts.json, beside its job caches:{"version", "key", "counts"}, wherekeyis a digest of the key_COUNTSuses (its roots, its job roots,workspace.headsof them, the run records' ids and states). After a start the file answers while that key matches, and no job is read. The key now also carries the catalogue's signature, in memory and on disk.The open workspace is never stored or read from the file. A workspace with a job still going is counted as before, and its file is removed. A moved head (a job added, removed or rewritten, or a
parse.SCHEMAorworkspace.SCHEMAchange, which the heads carry), a changed root, a changed run record, a changed catalogue or anotherCOUNTS_VERSIONleaves the file unused, and the workspace is counted again and the file rewritten. Refresh (clear_cache) removes it with the job caches.One file per workspace rather than a summary per job: it is the smallest thing the page needs, and it is keyed by what the in-memory counts already trust. It is plain JSON with a version, job-level only, so a later job index can replace it.
Touches
backend:
app/nullius/workspace.py(stored_counts,store_counts;n_cachedandclear_cacheskip the file). Web:app/web/workspaces.py(_counts). Tests:app/tests/test_workspace.py,app/ui_tests/test_run_routes.py. Docs:docs/how-it-works.md(the file in the workspace's table).Verified
Backend suite: 3215 tests in 169 modules, OK. Route suite: 719 tests in 61 modules, OK. Both in a rootless
python:3.12container.New tests:
workspace.job_from_dictandparse.parse_jobpatched to fail;COUNTS_VERSIONeach make the stored counts unused and the workspace counted again; the counts then equal a fresh count;/workspacesof the open, a closed and a running workspace are the same from the file as with no file at all;stored_countsrefuses another key, another version and malformed files;n_cacheddoes not count the file; Refresh removes it.The first
/workspacesafter a start, on profiles from the generator in Workspaces: counting a workspace's runs decodes every trial of every job #309 (W workspaces of 20 ended Harbor jobs of 50 trials), main and this branch alternated on the same profile, 3 fresh server processes each in one rootlesspython:3.12container, median and range:/runsasked first/runsasked firstparse.SCHEMAchangeThe last three rows count every workspace again on both, as they should; one slow start in each is the machine, not the change.
cProfile of the first request with caches current at 20x20x50 (werkzeug
ProfilerMiddleware, which slows it down):What the branch's first request still spends beyond the next one is Jinja compiling the page's templates (1.28 s of 1.55 s under the profiler), which the first page of any process pays, and the open workspace's own load. With
/runsasked first,_countsis under 0.02 s.Risk
The stored counts trust the same key as the in-memory ones, so they share its limit (
workspace.heads): a file changed inside a trial folder of an ended job and nothing else is not seen, now across a restart as well. Refresh removes the file. A write that fails (a read-only workspace folder) fails the page, as a job cache write does. The file is new on disk: an older version never reads it, and only miscounts it as one more cached job inn_cached. Undone by a revert; the leftovercounts.jsonfiles are harmless and Refresh removes them.