perf(monitors): remove std::function heap allocs and use direct map find in pub-sub fanout#224
Merged
hoytech merged 1 commit intohoytech:masterfrom Apr 28, 2026
Conversation
…ind in pub-sub fanout
Owner
|
Nice one, thanks! I think this is a vestigial feature for when we supported prefix lookup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ActiveMonitors::processruns for every new event that is applied to live subscriptions. It previously looked up candidate monitor sets withupper_bound+prev+ awhileloop and astd::function<bool(const T&)>built from a lambda for each of id, author, each tag, and kind.Monitor indexes are installed with one
btree_mapentry per exact key (event id, author pubkey, tag spec string, kind). Keys are unique, and every call site only ever used an equality predicate (id == val, etc.). For such a map, the only matching node ism.find(key); the old walk could touch at most that same entry.This change replaces that path with a small templated
lookupMonitorshelper that callsfindand processes theMonitorSetwhen present. It removes per-eventstd::functionconstruction (and associated type erasure / allocation behavior) and simplifies the lookup logic with no change to which monitors are considered.Files:
src/ActiveMonitors.hMotivation and context
Live subscription fanout is on the hot path when the relay is under write load. Fewer temporary objects and a direct map lookup improve CPU and allocator pressure under realistic workloads, without changing Nostr semantics.
How has this been tested?
make -j4(full tree)processMonitorSetbody); no new tests added.Types of changes
Checklist