| 1 | # Benchmarks against git |
| 2 | |
| 3 | `run.py` does the same work with braid and with git on one machine and says |
| 4 | how long braid took as a fraction of git's time, or how large its store is |
| 5 | as a fraction of git's: **braid / git**. Below 1 means braid is faster or |
| 6 | smaller, above 1 that it is slower or larger. |
| 7 | |
| 8 | Braid publishes only these ratios, together with this script. Absolute |
| 9 | times, sizes and the description of the machine stay on the machine that |
| 10 | measured them. |
| 11 | |
| 12 | ## Running it |
| 13 | |
| 14 | ```bash |
| 15 | python3 bench/run.py # every scenario, full size |
| 16 | python3 bench/run.py --quick # small inputs: a smoke run, as CI does |
| 17 | python3 bench/run.py --only status,commit |
| 18 | python3 bench/run.py --list # the scenarios |
| 19 | python3 bench/run.py --markdown # also print the table as Markdown |
| 20 | ``` |
| 21 | |
| 22 | It needs a Unix-like system, Python 3.9 or newer (standard library only), |
| 23 | git, cargo and `du`. It builds braid with `cargo build --release` first; |
| 24 | `--braid PATH` uses a binary you already have. The full run fetches the |
| 25 | repository of the import scenario once from GitHub. |
| 26 | |
| 27 | Everything happens in a new temporary directory, removed at the end: |
| 28 | `--workdir DIR` puts it elsewhere and `--keep` keeps it. The script checks |
| 29 | that there is room for its inputs there before it starts. Your git |
| 30 | configuration is never read or written: every git command runs with |
| 31 | `GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1` and a fixed identity. |
| 32 | |
| 33 | The table goes to standard output. The raw measurements, every time of |
| 34 | every round, go to `bench/results/`, which git ignores. |
| 35 | |
| 36 | ## How it measures |
| 37 | |
| 38 | - **Alternating order.** Every case runs braid and git in turn: braid, git, |
| 39 | git, braid, braid, git, and so on; with three contestants, each takes |
| 40 | every place once in every three rounds. A machine that grows warmer, or |
| 41 | caches that fill, favour none of them. |
| 42 | - **Warm.** Each case first runs once or twice untimed, so that both tools |
| 43 | start with the file system cache holding their files. |
| 44 | - **What an agent runs.** A time is the wall-clock time of the commands, from |
| 45 | process start to exit, as an agent calling the command line would wait |
| 46 | for them. When a case takes two commands, such as `git add` and |
| 47 | `git commit`, their times add up. |
| 48 | - **Medians.** The ratio is braid's median over git's median. `spread` is the |
| 49 | smallest and the largest ratio of a single round, which shows how noisy |
| 50 | the machine was; `cpu` is the ratio of CPU time (user and system) instead |
| 51 | of wall time, which differs when one tool uses more cores than the other. |
| 52 | - **Same work.** Each scenario checks that both tools did the same thing: |
| 53 | the same files modified, the same number of commits made, the same |
| 54 | changesets listed. A failed check is reported as an error, never as a |
| 55 | number. |
| 56 | - **Git as installed.** Git runs with its defaults, except that automatic |
| 57 | garbage collection and maintenance are off in the repositories the |
| 58 | benchmark makes, so that they never land in a measurement, and that the |
| 59 | file system monitor and the untracked cache are off unless a case turns |
| 60 | them on. |
| 61 | |
| 62 | ## Scenarios |
| 63 | |
| 64 | ### import |
| 65 | |
| 66 | The source is [tmux](https://github.com/tmux/tmux) at its 3.5a release, |
| 67 | 10,287 commits, fetched once with git into a local bare repository whose |
| 68 | only branch is `main`. Three rounds of: |
| 69 | |
| 70 | - **history only:** `braid init` and `braid git import <source>` against |
| 71 | `git clone --no-local --bare <source>`; |
| 72 | - **history and a working copy:** the same followed by |
| 73 | `braid workspace add`, against `git clone --no-local <source>`. |
| 74 | |
| 75 | `--no-local` makes git go through its transport, building and indexing a |
| 76 | pack, instead of copying or hard-linking the source's files. Braid's import |
| 77 | also exports every commit again and compares the ids, so that the round |
| 78 | trip is bit for bit. |
| 79 | |
| 80 | `--source URL_OR_PATH` (with `--source-ref REF`) imports another |
| 81 | repository; `--quick` imports this repository's own history. |
| 82 | |
| 83 | ### status |
| 84 | |
| 85 | A generated tree of 100,000 files: three levels of directories, 25 files in |
| 86 | each directory, text of 100 to 3,000 bytes, the same bytes on every run. |
| 87 | Git checks it out from one commit, and braid imports that commit and checks |
| 88 | it out in a workspace. Nine rounds of `braid status` against `git status`, |
| 89 | twice: with git's untracked cache off, then with `core.untrackedCache=true`; |
| 90 | the file system monitor is off in both (no daemon). Two cases: a clean tree, |
| 91 | and 10 files spread over the tree with a line appended. |
| 92 | |
| 93 | ### commit |
| 94 | |
| 95 | In the same tree, one file gets a line appended and is committed: nine |
| 96 | rounds of `braid commit` against `git add <file>` and `git commit`, a |
| 97 | different file each round. Braid has no staging area: its commit scans the |
| 98 | working copy, as a status does, and records what changed. |
| 99 | |
| 100 | ### wide |
| 101 | |
| 102 | A single directory of 20,000 small files. Each round adds one new file at |
| 103 | the end of it and commits it, 200 rounds, three ways: |
| 104 | |
| 105 | - git: `git add <file>` and `git commit`; |
| 106 | - braid in a workspace: `braid commit`; |
| 107 | - braid without a working copy: `braid change create --set <file>=@<copy> |
| 108 | --land main`. |
| 109 | |
| 110 | The table gives the ratio of each braid way to git, and then whether the |
| 111 | cost of one commit grows with the directory: the same series, 30 rounds, |
| 112 | in directories of 2,500, 5,000 and 10,000 files, and for each tool the cost |
| 113 | of one commit with 20,000 files divided by its cost with 2,500. 1 means the |
| 114 | cost does not grow with the directory; a cost proportional to it would give |
| 115 | 8. The raw results also have the exponent of a fit of cost against size, and |
| 116 | how much the last quarter of the 200 commits differs from the first. |
| 117 | |
| 118 | ### agents |
| 119 | |
| 120 | N = 4, 8 and 16 agents start at once. Each makes K = 10 commits, appending a |
| 121 | line to its own file, and lands each one before the next: |
| 122 | |
| 123 | - braid: `braid commit` and `braid land`, each agent in its own workspace of |
| 124 | one repository; |
| 125 | - git: `git commit -a` and `git push`, each agent in its own clone of one |
| 126 | bare repository; a rejected push runs `git pull --rebase` and pushes |
| 127 | again. |
| 128 | |
| 129 | The time is the wall-clock time from the start until the last agent has |
| 130 | landed its last commit. Three rounds for each N, with new repositories each |
| 131 | time. The table also says how many times git retried a push, on average. |
| 132 | |
| 133 | ### store |
| 134 | |
| 135 | After the import, `du -sk` of `.braid/store` against `du -sk` of the bare |
| 136 | clone after `git gc --aggressive --prune=now`. The raw results also have the |
| 137 | sum of the file sizes alone, and the size of the clone before the gc. |
| 138 | |
| 139 | ### history |
| 140 | |
| 141 | On the imported repository, and on the bare clone after its gc: |
| 142 | |
| 143 | - `braid log -n 1000` against `git log --first-parent -n 1000 --format=%H`; |
| 144 | - `braid log -- <path>` against `git log --first-parent -- <path>`, for the |
| 145 | file that the most commits changed and for a file that one commit touched, |
| 146 | both listing every commit that touched it; |
| 147 | - `braid blame <path>` against `git blame --first-parent <path>`. |
| 148 | |
| 149 | Braid follows first parents, so git does too, and both list the same |
| 150 | changesets; the scenario checks it. A query that braid does not have yet is |
| 151 | skipped, and the table says so. |
| 152 | |
| 153 | ## Reading the ratios |
| 154 | |
| 155 | - 0.5 means braid took half of git's time; 2 means twice as long. For the |
| 156 | store, 3 means three times as many bytes on disk. |
| 157 | - A ratio holds for the machine it was measured on. Another file system, |
| 158 | another number of cores, or another git version moves it, sometimes a lot: |
| 159 | run the script on your machine before relying on a number. |
| 160 | - Look at `spread` before trusting a ratio. A wide spread means the machine |
| 161 | was busy; run again with more rounds (`--rounds N`), or, on a machine |
| 162 | shared with other work, with `--max-load N`, which waits before each timed |
| 163 | round until the load average of the last minute is below N. It changes |
| 164 | when rounds run, never what they measure, and the raw results say how |
| 165 | long it waited. |
| 166 | - `--quick` inputs are far too small to compare anything. It only checks |
| 167 | that every scenario still runs. |
| 168 | |
| 169 | ## What it does not measure |
| 170 | |
| 171 | - Cold caches: every case runs with warm caches. |
| 172 | - Git with the file system monitor daemon, or with `feature.manyFiles`. |
| 173 | - Transfers between machines: braid has no server yet. |