Skip to content

rabbit_khepri: Optimize cleanup in topic binding projection (backport #15214)#15237

Merged
dumbbell merged 1 commit intov4.2.xfrom
mergify/bp/v4.2.x/pr-15214
Jan 9, 2026
Merged

rabbit_khepri: Optimize cleanup in topic binding projection (backport #15214)#15237
dumbbell merged 1 commit intov4.2.xfrom
mergify/bp/v4.2.x/pr-15214

Conversation

@mergify
Copy link
Copy Markdown

@mergify mergify bot commented Jan 9, 2026

Why

Before this patch, the projection function that managed the topic bindings graph only kept track of "topic word -> topic word" = "this node ID". Reading and updating this graph was efficient.

However, deleting a node in this graph was expensive because it used ets:match/3 to determine if an edge was pointing to nothing and could be reclaimed. ets:match() does a full scan of the table. On my laptop, this scan took 20 ms with 100k topic bindings, thus >30 minutes to delete all of them.

How

The new projection function tracks the number of children a target node has as well. This way, it knows that if this counter reaches 0, the edge can be reclaimed.

The same test with 100k topic bindings takes 3.5 seconds to delete them.


This is an automatic backport of pull request #15214 done by Mergify.

@dumbbell dumbbell marked this pull request as draft January 9, 2026 08:49
[Why]
Before this patch, the projection function that managed the topic bindings
graph only kept track of "topic word -> topic word" = "this node ID".
Reading and updating this graph was efficient.

However, deleting a node in this graph was expensive because it used
`ets:match/3` to determine if an edge was pointing to nothing and could
be reclaimed. `ets:match()` does a full scan of the table.

On my laptop, this scan took 20 ms with 100k topic bindings, thus >30
minutes to delete all of them.

[How]
The new projection function tracks the number of children a target node
has as well. This way, it knows that if this counter reaches 0, the edge
can be reclaimed.

The same test with 100k topic bindings takes 3.5 seconds to delete them.

(cherry picked from commit 612d93d)
@dumbbell dumbbell force-pushed the mergify/bp/v4.2.x/pr-15214 branch from 0dd4f55 to fa4670b Compare January 9, 2026 09:14
@dumbbell dumbbell marked this pull request as ready for review January 9, 2026 10:08
@dumbbell dumbbell merged commit d6e3146 into v4.2.x Jan 9, 2026
575 of 577 checks passed
@dumbbell dumbbell deleted the mergify/bp/v4.2.x/pr-15214 branch January 9, 2026 10:08
@dumbbell dumbbell added this to the 4.2.3 milestone Jan 9, 2026
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.

1 participant