Require rbyd_/mdir_ out-pointers to be non-null

This makes all rbyd_/mdir_ out-pointers required, dropping all of the
internal copies needed to make lookup/namelookup/pathlookup/etc work.

Previously, the -- rough -- rule was to make out-pointers generally
optional (lfsr_data_read and other struct initers being notable
exceptions), the idea being you can opt-out of stack allocations where
possible.

In practice this kind of backfired, with many internal functions needing
redundant stack allocations in case the relevant parameter is NULL
(lfsr_btree_lookupleaf being an excellent example).

---

As an alternative rule, I think we should only expect optional
out-pointers for things you would pass-by-value (lfsr_rid_t, lfsr_tag_t,
lfsr_data_t, etc).

I've also developed a habit of naming optional out-pointers with a
trailing underscore_, to hopefully make this subtlety a bit less subtle.

This claws back all of the stack cost of BNAMEs/MNAMEs, and most of the
code cost:

           code          stack          ctx
  before: 35888           2480          640
  after:  35780 (-0.3%)   2408 (-2.9%)  640 (+0.0%)

Though we still have more function calls than we started with
(lfsr_mtree_*lookup mtree -> mdir lookups).
This commit is contained in:
Christopher Haster
2025-04-28 18:28:46 -05:00
parent 27dd339a6a
commit 6cde75d671
2 changed files with 74 additions and 124 deletions
+4 -2
View File
@@ -3889,9 +3889,10 @@ code = '''
// a c d g h i k
// ^
lfsr_bid_t split_bid;
lfsr_rbyd_t split_rbyd;
lfs_scmp_t cmp = lfsr_btree_namelookupleaf(&lfs, &btree,
0, name, 3,
&split_bid, NULL, NULL, NULL, NULL, NULL);
&split_bid, &split_rbyd, NULL, NULL, NULL, NULL);
assert(cmp >= 0);
assert(cmp != LFS_CMP_EQ);
if (cmp > LFS_CMP_EQ) {
@@ -4082,10 +4083,11 @@ code = '''
// a c d g h i k
// ^
lfsr_bid_t split_bid;
lfsr_rbyd_t split_rbyd;
lfsr_bid_t split_weight;
lfs_scmp_t cmp = lfsr_btree_namelookupleaf(&lfs, &btree,
0, name, 3,
&split_bid, NULL, NULL, NULL, &split_weight, NULL);
&split_bid, &split_rbyd, NULL, NULL, &split_weight, NULL);
assert(cmp >= 0);
assert(cmp != LFS_CMP_EQ);
if (cmp > LFS_CMP_EQ) {