Skip to content

Conversation

@martinsumner
Copy link

* Simplify and reduce the number of compares

form_slot is split between the no_lookup part (all form_slot loops start assuming no_lookup) and the lookup part (now in form_slot_lookup).  This reduces the branches required in each loop.

The first key check is now made at the end and only when ncessary.

The check for the ?IDX tag is now done explicitly rather than through another function call.

The key_dominates function has been simplified and reorganised - passing the reaping responsibility back up to form_slot, and reducing the branches and ensuring the first condition is the most common (K2 is the next key - as KVL1 is a small list merging into the bigger KVL2).

Frequently called functions are now smaller, and so are inlined.

* Refactor accumulate_positions

Two issues resolved:

- accumulation was in the wrong way (prepending, not appending a binary) - difference according to epro is 0.17 vs 0.22 microsecond per call;
- form_slot rolls over the list, then accumulate_positions re-rolls.  Now accumulate_position is extracted out as a function so that form_slot can also do this - so there ius no double-fold over the list.

* Update leveled_sst.erl

* Add shortcut in find_nextkeys/6

This loop is a major factor in the performance of any long-running query or fold.

Commonly, it would be normal to expect the "next key" to be most commonly found at the lower level.  This implements a shortcut, whereby when the next key is at the bottom level, there is no need to check all the other levels next time round.

* Don't recalculate length each loop

Instead count down the keys being added to the iterator

* Improve efficiency

Use maps:update/3 in preference to maps:update_with/3 due to improved speep, and short-circuit loop wherever possible.

* Remove type-check in guard

Not required by eqwalizer or dialyzer

* Format issue
@martinsumner martinsumner merged commit 2a2795a into openriak-3.4 Oct 20, 2025
2 checks passed
@martinsumner martinsumner deleted the mas-d34-upstream.pr482 branch October 20, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants