btree: Resurrected btree leaf caching
This is an indulgence to simplify the upcoming auxiliary btree work.
Brings back the previously-reverted per-btree leaf caches, where each
lfs3_btree_t keeps track of two rbyds: The root and the most recently
accessed leaf.
At the surface level, this optimizes repeated access to the same btree
leaf. A common pattern for a number of littlefs's operations that has
proven tricky to manually optimize:
- Btree iteration
- Pokes for our crystalization heuristic
- Checksum collision resolution for dids and (FUTURE) ddkeys
- Related rattrs attached to a single bid
But the real motivation is to drop lfs3_btree_*lookupleaf and simplify
the internal APIs. If repeated lfs3_btree_lookup*s are already
efficient, there's no reason for extra leaf-level APIs, and in theory
any logic that interacts with btrees will be simpler.
---
This comes at a cost (humorously about the same amount as the
tag-returning refactor, if you ignore the extra 28 bytes of ctx).
Unsurprisingly, increasing the size of lfs3_btree_t has the biggest
impact on stack and ctx:
code stack ctx
before: 36084 2336 656
after: 36784 (+1.9%) 2400 (+2.7%) 684 (+4.3%)
Also note from the previous commit messages: Btree leaf caching has
resulted in surprisingly little performance improvement for our current
benchmarks + implementation. It turns out if you're dominated by write
cost, optimizing btree lookups -- which already skip rbyd fetches, has
barely noticeable impact.
---
A note on reverting!
Eventually (after the auxiliary btree work) it will probably make sense
to revert this -- or at least provide a non-leaf-caching build for
code/RAM sensitive users.
I don't think this should be reverted as-is. Instead, I think we should
allow the option to just disable the leaf cache, while keeping the
simpler internal API. This would give us the best of all three worlds:
- A small code/RAM option
- Optimal btree iteration/nearby-lookup performance
- Simpler internal APIs
The only reason this isn't already implemented is because I want to
avoid fragmenting the codebase further while we're still in development
mode.
This commit is contained in:
+12
-12
@@ -98,10 +98,10 @@ code = '''
|
||||
}
|
||||
printf("]\n");
|
||||
printf("btree: w%d 0x%x.%x\n",
|
||||
btree.weight,
|
||||
btree.blocks[0],
|
||||
btree.trunk);
|
||||
assert(btree.weight == sim_size);
|
||||
btree.r.weight,
|
||||
btree.r.blocks[0],
|
||||
btree.r.trunk);
|
||||
assert(btree.r.weight == sim_size);
|
||||
|
||||
uint8_t buffer[4];
|
||||
lfs3_bid_t bid_;
|
||||
@@ -2053,10 +2053,10 @@ code = '''
|
||||
}
|
||||
printf("]\n");
|
||||
printf("btree: w%d 0x%x.%x\n",
|
||||
btree.weight,
|
||||
btree.blocks[0],
|
||||
btree.trunk);
|
||||
assert(btree.weight == sim_size);
|
||||
btree.r.weight,
|
||||
btree.r.blocks[0],
|
||||
btree.r.trunk);
|
||||
assert(btree.r.weight == sim_size);
|
||||
|
||||
uint8_t buffer[4];
|
||||
lfs3_bid_t bid_;
|
||||
@@ -4010,10 +4010,10 @@ code = '''
|
||||
}
|
||||
printf("]\n");
|
||||
printf("btree: w%d 0x%x.%x\n",
|
||||
btree.weight,
|
||||
btree.blocks[0],
|
||||
btree.trunk);
|
||||
assert(btree.weight == sim_size);
|
||||
btree.r.weight,
|
||||
btree.r.blocks[0],
|
||||
btree.r.trunk);
|
||||
assert(btree.r.weight == sim_size);
|
||||
|
||||
uint8_t buffer[4];
|
||||
lfs3_bid_t bid_;
|
||||
|
||||
Reference in New Issue
Block a user