SharedFileList: O(N²) → O(N log N) keyword indexing on Reload (#302) - #566
Merged
mrjimenez merged 1 commit intoMay 11, 2026
Merged
Conversation
…dKeyword (amule-project#302) CPublishKeywordList::FindKeyword() did a linear scan of the keyword list on every call. AddKeyword() calls FindKeyword() once per keyword, and CSharedFileList::Reload() calls AddKeywords() once per shared file at startup, so the cost is O(N²) in the keyword set size. With a 10–100k shared library that lights one core for minutes during init (per the backtrace in amule-project#302). Add a std::map<wxString, list-iterator> secondary index alongside the existing list. The list stays canonical (its insertion order is load-bearing for GetNextKeyword()'s round-robin publish cursor); the map is updated in lockstep on every mutation (Add/Remove/RemoveAll/ PurgeUnreferenced) so iterators in the map stay valid with the list. FindKeyword now does a single map lookup — O(log N) — turning the startup hot path from O(N²) to O(N log N). For 100k keywords that's ~1.7M comparisons instead of ~10^10. Reported by @mifritscher2 on amule-project#302.
|
Wow, the fix was even more effective than I was prepared for debugging^^ The start time (start of amule until connected to a server) was dropped from ca. 20-30 minutes to about 3 min - the GUI being always responsive. Thanks! |
got3nks
added a commit
to got3nks/amule
that referenced
this pull request
Jul 23, 2026
…-project#566) Follow-up to amule-project#565: surface the memory-mapped file I/O preference on the REST API. files.mmap_supported is a read-only daemon capability (mirrors upnp_available), read from the EC_TAG_FILES_MMAP_SUPPORTED tag; files.mmap_enabled is the runtime value. A PATCH that sets mmap_enabled is rejected with 409 when the connected daemon lacks mmap support, so the option is only writable against a core that can actually use it. Updates docs/api/REFERENCE.md and the 15-preferences-patch curl smoke (round-trip on a mmap-capable daemon; the 409 capability gate otherwise).
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.
Summary
CPublishKeywordList::FindKeyword()did a linear scan of the keyword list on every call.AddKeyword()calls it once per keyword, andCSharedFileList::Reload()callsAddKeywords()once per shared file at startup — so the cost is O(N²) in the keyword set size. On a 10–100k shared library this lights one CPU core for minutes during init (backtrace from @mifritscher2 on #302).Fix
Add a
std::map<wxString, CKeyWordList::iterator>secondary index alongside the existingstd::list. The list stays canonical — its insertion order is load-bearing forGetNextKeyword()'s round-robin publish cursor. The map is maintained in lockstep on every mutation site (AddKeyword,RemoveKeyword,RemoveAllKeywords,PurgeUnreferencedKeywords), so the iterators it stores stay valid with the list (std::listiterators are stable across other inserts/erases — only the erased iterator itself is invalidated).FindKeywordnow does a single map lookup, O(log N) — turning the startup hot path from O(N²) to O(N log N). For 100k keywords that's ~1.7M comparisons instead of ~10¹⁰.Caveats
Independent from #560 / #561; addresses a separate hot spot on the same issue. Ordering is unchanged for the round-robin publish path, so no behavioural change at runtime.