diff --git a/docs/spec/perf/19-engine-v.md b/docs/spec/perf/19-engine-v.md index 552b58c..e0c2099 100644 --- a/docs/spec/perf/19-engine-v.md +++ b/docs/spec/perf/19-engine-v.md @@ -684,3 +684,22 @@ With `--confirm all`, `init` and `std` give 0 disagreements, and the 225 Arena t The parse now uses about 970 instructions for each line, and nano-lean uses about 390 for each line of its import (18.4). The two changes remove only the tests around the work. The rest of the cost is the work: the hash and the probe of each node, the side record, and the read of each number and each fixed text with the checks of the bounds and the overflows. A parse of at most 3 G (18.5) thus needs a different method, and not smaller steps of this method. On this machine (macOS), two runs of the same build of the parse differ by up to 0.4 G of instructions, so the local count cannot measure a change of this size. Each measure of 19.25 is from callgrind in CI. + +## 19.26 A mask of the loose bound variables in the store + +nano-lean keeps a 32-bit mask of the loose bound variables in each term (09.3). Engine V makes this mask with `v_mask_at`, which walks the term and keeps the result in a direct-mapped memo. On `init`, `v_mask_at` has 32.81 M calls and uses about 2.0 G of self cost and 2.49 G of inclusive cost (19.23). The branch `perf/store-mask` measures if a mask in the store removes this cost. + +On the branch, the store keeps a 64-bit mask for each node in one array for each kind, next to the side records. `intern_expr` makes the mask of a new node from the masks of its fields, with the rules of `v_mask_at` and with no limit of the depth. `Store::expr_mask` reads the mask of a handle, and `v_mask_at` uses it before the memo. A node of a shared base has no mask, so `v_mask_at` then walks the term as before. + +The counts are from callgrind in CI, without the portable `sha256::compress` (08): + +| Input | main (#347) | `perf/store-mask` | +|---|---|---| +| `init` | 43.93 G | 44.62 G (+1.6%) | +| `std` | 75.94 G | 77.03 G (+1.4%) | + +With `--confirm all`, `init` and `std` give 0 disagreements, and the 225 Arena tests give the expected verdict. + +The self cost of `v_mask_at` on `init` goes down from about 2.0 G to about 0.7 G, but `Store::expr_mask` uses about 2.1 G, or about 48 instructions for each call. A read of the mask decodes the handle, tests the tier and the base, and does the bounds checks, as a read of a side record does (19.24). This cost is not less than the cost of the probe of the memo that it replaces, because most calls of `v_mask_at` hit the memo. The masks of the new nodes also add cost to `intern_expr` and to the parse. The array adds 8 bytes for each node, or about 49 MB on `init`. + +The mask of nano-lean is cheap because a term of nano-lean is a pointer to its fields, so the mask is one load. In the store of 04, each read of a node or a side record costs about 22 instructions (19.24). A cache of a property in the store thus does not make engine V faster when engine V already has a memo of that property. The branch is not merged (M13, #344). The next M13 steps make fewer reads of the store, and do not move a memo into the store.