Skip to content

Fix keep_while performance regressions#353

Merged
dumbbell merged 3 commits into
v0.17.xfrom
fix-keep_while-performance-regression
Jan 7, 2026
Merged

Fix keep_while performance regressions#353
dumbbell merged 3 commits into
v0.17.xfrom
fix-keep_while-performance-regression

Conversation

@dumbbell
Copy link
Copy Markdown
Collaborator

@dumbbell dumbbell commented Jan 7, 2026

This branch fixes two performance issues related to keep_while conditions:

  1. How we squash version bumps after keep_while conditions-related changes are applied.
  2. How we handle many deleted tree nodes that are grand-children of another deleted tree node, or deleted tree nodes that are siblings.

See each commit for the full explanation.

The third commit adds a "testcase" that verifies the performance of keep_while conditions is ok.

@dumbbell dumbbell added this to the v0.17.4 milestone Jan 7, 2026
@dumbbell dumbbell self-assigned this Jan 7, 2026
@dumbbell dumbbell added the bug Something isn't working label Jan 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.62%. Comparing base (a266e2d) to head (b3dcbf7).
⚠️ Report is 4 commits behind head on v0.17.x.

Files with missing lines Patch % Lines
src/khepri_tree.erl 96.07% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           v0.17.x     #353      +/-   ##
===========================================
+ Coverage    86.39%   86.62%   +0.22%     
===========================================
  Files           22       22              
  Lines         3477     3514      +37     
===========================================
+ Hits          3004     3044      +40     
+ Misses         473      470       -3     
Flag Coverage Δ
erlang-26 86.59% <96.07%> (+0.22%) ⬆️
erlang-27 86.59% <96.07%> (+0.51%) ⬆️
erlang-28 86.59% <96.07%> (+0.51%) ⬆️
os-ubuntu-latest 86.62% <96.07%> (+0.22%) ⬆️
os-windows-latest 86.62% <96.07%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

[Why]
When a tree uses `keep_while` conditions heavily, the previous
implementation of `squash_version_bumps_after_keep_while()` was really
expensive.

This was due to the fact the for each modified node, we would loop over
all entries of the `AppliedChanges` map to evaluate if the modified node
got its `child_list_version` bumped twice.

[How]
Now, we handle this squash at the end of the handling of met
`keep_while` conditions.
[Why]
When there are many nodes delete because of an "expired" `keep_while`
conditon, the previous implemention would walk the tree for each deleted
tree node. This could be very expensive, even a waste of resources when
deleted tree nodes were siblings or they would be automatically deleted
because a parent was too.

[How]
Before looping over all the paths to delete, we convert them to patterns
if possible. In other words, paths that are children of an already
deleted parent are dropped and siblings are put together in a single
pattern.
[Why]
These new test cases verify the performance of `keep_while` handling
after the previous two fixes. They only ensure there are no regressions.
They do not verify correctness that much.

Submitted by: Michal Kuratczyk (@mkuratczyk)
@dumbbell dumbbell force-pushed the fix-keep_while-performance-regression branch from b75f834 to b3dcbf7 Compare January 7, 2026 17:06
@dumbbell dumbbell marked this pull request as ready for review January 7, 2026 17:17
@dumbbell dumbbell merged commit cdc42a7 into v0.17.x Jan 7, 2026
26 checks passed
@dumbbell dumbbell deleted the fix-keep_while-performance-regression branch January 7, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant