Skip to content

statement-store: index subscriptions by topic for efficient statement matching#3281

Open
AndreiEres wants to merge 2 commits into
mainfrom
ae-statement-topic-index
Open

statement-store: index subscriptions by topic for efficient statement matching#3281
AndreiEres wants to merge 2 commits into
mainfrom
ae-statement-topic-index

Conversation

@AndreiEres

Copy link
Copy Markdown
Contributor

Closes #3144
Closes #3147

Statements from the network were matched against every active subscription, giving O(n_statements × n_subscriptions × topic_factors) complexity — a node re-scanned all subscriptions even for statements no one filtered on.

Add a reverse topic -> subscriptions index (plus a wildcard set for Any and empty MatchAll, which match everything). For each statement, matching now considers only the wildcard subscriptions and those sharing one of its topics, then applies the exact per-subscription filter and dedup via accept. Filter semantics are unchanged; the index only narrows the candidate set.

self.wildcard.insert(id.clone());
}
// An empty `MatchAll` filter matches every statement.
TopicFilter::MatchAll(topics) if topics.is_empty() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just reject this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because, feels like an unintended usage of the API, I'm fine with keep it as it is.

for id in &candidates {
let sub = subscriptions
.get_mut(*id)
.expect("by_topic/wildcard only reference live subscriptions; qed");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
.expect("by_topic/wildcard only reference live subscriptions; qed");
.expect("`candidates` is a subset of `subscriptions`; qed");

@mergify

mergify Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants