CCF icon indicating copy to clipboard operation
CCF copied to clipboard

KV: support for ordered maps

Open jumaffre opened this issue 4 years ago • 2 comments

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)

image

We should replace the CHAMP with the RB map, and do the following (in this order):

  • [x] 1. Add comparison benchmark between std::map (and std::unordered_map) to the existing map_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() and right() 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()

jumaffre avatar Oct 13 '21 15:10 jumaffre

Linking #4789 and #4788

jeffa5 avatar Dec 22 '22 11:12 jeffa5

  • [ ] 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.

achamayou avatar Jan 23 '23 17:01 achamayou