CCF
CCF copied to clipboard
KV: support for ordered maps
The underlying implementation of the a key-value map currently uses a CHAMP, which is fast compared to the original Red-Black tree implementation (see benchmark results: https://github.com/microsoft/CCF/issues/2814#issuecomment-940099829), but does not provide ordered access to the element stored in it. This is an issue for determinist execution (see https://github.com/microsoft/CCF/issues/2814) and would also prevent us from implementing an efficient KV range API. Moreover, the performance difference between the two implementations do not seem to substantially affect the end-to-end performance of CCF (especially that the RB map doesn't seem to be as optimised as it could be):
Show cimetrics output (recorded here for posterity)

We should replace the CHAMP with the RB map, and do the following (in this order):
- [x] 1. Add comparison benchmark between
std::map(andstd::unordered_map) to the existingmap_bench, so that we assess how much optimisation we can aim for for the RB map. - [ ] 2. Optimise RB map implementation accordingly (in particular the calls to
left()andright()which copy the root pointers). - [x] 3. Add snapshotting capability for RB map (with backwards compatibility with snapshots created in 1.x).
- [ ] 4. Improve
foreach()for RB map, using iterators to be able to deal with committed state vs. local writes. - [ ] 5. Replace CHAMP with RB map in CCF.
- [x] 6. Add
range(start_key, end_key)API. - [ ] 7. Typed ranges (see https://github.com/microsoft/CCF/issues/4232)
- [ ] 8. Support for
rb::map::remove()
Linking #4789 and #4788
- [ ] Revisit instances of foreach in built-in endpoints, particularly the replay protection code added in #4823 to see if they can't be optimised by switching to ordered maps when they become available.