Skip to content

Latest commit

 

History

History
159 lines (125 loc) · 6.97 KB

performance.md

File metadata and controls

159 lines (125 loc) · 6.97 KB

Working-tree performance (status and diff)

Week 8, Module 2. Numbers below are best-of-5 wall-clock seconds for one call of cmd_status and cmd_diff on a generated repository.

How it was measured

  • Repository: 3000 small files (40 lines each, in 50 folders) plus one 20000-line file, all committed.
  • Benchmark: bench_working_tree.py (--profile shows where the time goes).
  • Machine: MacBook Air (Apple silicon), Python 3.13.5.
  • Command: PYTHONPATH=. python3 bench_working_tree.py

Before

main's code. Old and new were run alternately, one right after the other, so both saw the same machine conditions.

Situation status diff
nothing changed 0.133 s 0.122 s
1 small file changed 0.125 s 0.121 s
50 small files changed 0.123 s 0.125 s
+ big file, 2 edits 0.123 s 0.131 s
+ big file, 500 scattered edits 0.125 s 0.223 s

Where the time went

With 3000 files, status and diff take about the same time however many files changed, so the cost is per file visited, not per change. The profile of the "nothing changed" case showed:

  • os.getcwd called 6003 times (twice per file), about 0.05 s of the 0.19 s profiled run. Cause: the file walk called os.path.relpath once for every file. WorkingTree uses the relative root ".", so each call asked the operating system for the current directory twice.
  • Reading the files (open, 3055 calls, about 0.03 s) and the executable-bit check (os.access, 3001 calls, about 0.01 s). Both are needed to decide whether a file changed.
  • Line diffing (Myers) only matters for the big file with 500 scattered edits, where diff rises from about 0.13 s to 0.23 s. That cost is real work, not repeated work.

Change made

One bounded fix: the three file walks (status, diff, and the added-file check) now share walk_working_files(), which works out the relative folder once per folder (about 50 times) instead of once per file (3000 times).

Nothing else changed. Every file is still read and hashed, so a same-size edit with the original timestamp is still found (regression test: test_same_size_edit_with_preserved_timestamp_is_still_found). Nothing is cached, and status and diff still write nothing to the repository.

After

Same command, on the code with walk_working_files().

Situation status diff
nothing changed 0.070 s 0.064 s
1 small file changed 0.066 s 0.064 s
50 small files changed 0.066 s 0.066 s
+ big file, 2 edits 0.070 s 0.071 s
+ big file, 500 scattered edits 0.066 s 0.166 s

With many files, status and diff take about 45% less time (about 0.12 s down to 0.066 s). Every row improves by roughly the same 0.055 s, which matches the time the profile showed going to the 6003 getcwd calls. The 500-edit diff improves by less (0.223 s to 0.166 s) because most of its time is the Myers diff, which was not changed.

Re-run

Run these numbers again with the shared benchmark (#47) once it is merged.

Object-storage performance

How it was measured

The shared packfile fixture is generated by scripts/benchmark_packfiles.py. Each run uses a fresh temporary repository with 512 deterministic blob objects. Each blob contains a unique 22-byte prefix followed by 2,048 generated bytes (--payload-size 2048), for 2,070 bytes total. This is an M1 storage fixture, not the approximately 1,000-file / 100-commit end-to-end fixture still tracked in #47 and #58. It does not measure networking or history traversal.

On Windows from the repository root:

.\.venv\Scripts\python.exe scripts\benchmark_packfiles.py --profile
.\.venv\Scripts\python.exe scripts\benchmark_packfiles.py --no-cache --profile

Earlier reported results

Recorded on Python 3.11.9, Windows 10 build 26200, at bc3ed1e. This revision predates the 64-entry cache bound and inode checks in #71; these measurements compare metadata caching with --no-cache, not those later additions:

Measurement Cached (bc3ed1e) Uncached comparison
Loose object write time 583.413 ms 591.064 ms
Loose stored bytes 27,534 27,534
Loose fresh-store read time 9,084.883 ms 1,772.944 ms
Pack time 145.947 ms 136.304 ms
Retained loose bytes after packing 27,534 27,534
Pack bytes 33,179 33,179
Index bytes 18,444 18,444
Packed-only fresh-store read time 204.085 ms 4,440.836 ms
Three repeated packed reads 0.725 s profiled 20.570 s profiled

The uncached comparison disables only the per-store index metadata cache; it retains the same object and pack validation. The packed-only repeated-read comparison is the bounded optimization target: cached metadata avoids repeated full-pack parsing and decompression while selected records remain validated on each read. Loose reads and storage sizes are otherwise unchanged. The cache is bounded and does not cache object bytes, so filesystem discovery and loose-file latency remain limitations.

Reproduction of #71

Run on 2026-11-18 with production code and benchmark script at d00685dc1d853c22eb3bb744db23929b3d6fcecf, Python 3.13.5, macOS 26.6.2 on arm64. Only documentation and regression tests differed from that revision. The following commands ran sequentially with no test suite running concurrently:

.venv/bin/python scripts/benchmark_packfiles.py --profile
.venv/bin/python scripts/benchmark_packfiles.py --no-cache --profile

Both runs use the default 512-object / 2,048-byte payload parameter. A fresh store means a new ObjectStore instance, not a cold filesystem cache. Each command creates its own temporary repository. The fresh read traverses all objects once; the profiled repeated read uses another new store for three passes. Timings below are one observational run per configuration, not a statistical claim or a CI threshold.

Measurement Cached --no-cache
Loose object write time 83.924 ms 82.399 ms
Loose stored bytes 27,534 27,534
Loose fresh-store read time 13.691 ms 13.947 ms
Pack time 23.250 ms 23.273 ms
Retained loose bytes after packing 27,534 27,534
Pack bytes 33,179 33,179
Index bytes 18,444 18,444
Packed-only fresh-store read time 32.947 ms 2,151.480 ms
Three repeated packed reads, profiled 0.146 s 8.975 s

--no-cache bypasses metadata reuse on the same code and retains complete pack/index validation. It is a controlled comparison, not an exact checkout of an earlier implementation. The cache bound and inode checks protect resource use and replacement detection; this one-pack fixture does not isolate their performance effect. Packed-only storage is 51,623 bytes here, larger than the 27,534-byte loose-only representation. Packing retains loose originals until the benchmark deliberately removes them in its disposable fixture. Neither these measurements nor the older Windows runs complete the shared project benchmark in #47/#58.