Repository navigation
feat(acceleration): BackendRegistry O(n²) → O(k) backend selection index - #4620
Merged
Merged
Conversation
3 tasks
…imization (Issue #236) - Add RegisteredBackend struct to compute_backend.h with pre-cast typed interface pointers (base, vectorPtr, graphPtr, geoPtr, matrixPtr) - Add typeIndex_ (unordered_map<BackendType, RegisteredBackend>) to BackendRegistry - registerBackend(): populate typeIndex_ with one dynamic_cast per interface at registration time — never in the hot query path - selectTyped<T>(): now O(|kFallbackOrder|) using map lookup instead of O(|kFallbackOrder| × |backends|) nested scan with dynamic_cast per iteration - getBackend(): O(1) hash-map lookup via typeIndex_ - getBestVectorBackend/GraphBackend/GeoBackend/MatrixBackend(): use typed pointers from typeIndex_ directly — zero dynamic_cast calls - selectBackendFor(): keeps original linear scan (backward compatible for multi-backend-per-type correctness with generic IComputeBackend* return) - shutdownAll(): clears typeIndex_ alongside backends_ - Add 7 new type-index correctness tests to test_backend_selection_matrix.cpp - Mark all 3 implementation notes as [x] in FUTURE_ENHANCEMENTS.md files - Add Phase 5 ROADMAP entry for the optimization Agent-Logs-Url: https://github.com/makr-code/ThemisDB/sessions/e6e8c47e-38ac-4f08-bc8c-a6fa076dfda9 Co-authored-by: makr-code <[email protected]>
Copilot
AI
changed the title
[WIP] Implement BackendRegistry: O(n²) Backend Selection Index
feat(acceleration): BackendRegistry O(n²) → O(k) backend selection index
Apr 13, 2026
makr-code
marked this pull request as ready for review
April 13, 2026 13:35
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.
Eliminates the O(|kFallbackOrder| × |backends|) nested loop with per-iteration
dynamic_castcalls in backend selection. Every typed selector (selectVectorBackendFor,getBestGraphBackend, etc.) previously scanned all registered backends (~15) for each of 13 fallback priority levels and cast on each match. With ~15 backends this is negligible today, but the pattern scales poorly and thedynamic_castcost accumulates on every query.Changes
include/acceleration/compute_backend.hRegisteredBackendstruct:base,vectorPtr,graphPtr,geoPtr,matrixPtr— raw pointers into heap-owned backends, set once at registrationstd::unordered_map<BackendType, RegisteredBackend> typeIndex_toBackendRegistryprivate sectionsrc/acceleration/backend_registry.cppregisterBackend(): onedynamic_castper interface per registration (first-wins per type/interface) to populatetypeIndex_selectTyped<T>(): replaces nested loop with O(|kFallbackOrder|) hash-map lookup + stored typed pointer; zero hot-pathdynamic_cast. AddedgetTypedPtr<T>specializations for all 5 interface typesgetBackend(type): O(n) → O(1) viatypeIndex_.find()getBest*Backend(): iteratekFallbackOrder, index lookup, return stored typed pointer — nodynamic_castselectBackendFor(): retains original linear scan; genericIComputeBackend*semantics require seeing all per-type registrations (e.g.CPUGraphBackendalongsideCPUVectorBackendunderBackendType::CPU)shutdownAll(): clearstypeIndex_alongsidebackends_Multiple CPU backends sharing
BackendType::CPUare handled correctly:typeIndex_[CPU].vectorPtr→CPUVectorBackend*,typeIndex_[CPU].graphPtr→CPUGraphBackend*, etc.tests/test_backend_selection_matrix.cppTypeIndex_*tests verifying correct typed-pointer aggregation for all four CPU backends sharingBackendType::CPU, distinct per-interface returns, and capability declarationsDocumentation
FUTURE_ENHANCEMENTS.md/future_enhancements.md: all 3 implementation notes marked[x]ROADMAP.md: Phase 5 entry addedLinked Issues
Closes #236
Type of Change
Breaking Change Checklist
VERSIONandCMakeLists.txtdocs/migration/### Removed/### Changedsection updatedTesting
📚 Research & Knowledge (wenn applicable)
/docs/research/angelegt?/docs/research/implementation_influence/eingetragen?Relevante Quellen:
Checklist
[Unreleased]