perf(memory): hoist loop-invariant HRR encodes out of retrieval loops - #20
Open
spfcraze wants to merge 1 commit into
Open
perf(memory): hoist loop-invariant HRR encodes out of retrieval loops#20spfcraze wants to merge 1 commit into
spfcraze wants to merge 1 commit into
Conversation
FactRetriever.search() re-encoded the query vector once per candidate, related() re-encoded both role atoms once per fact row, and probe() re-encoded the role-content atom once per row. All three encoders are deterministic (SHA-256 counter blocks), so the hoisted vectors are bit-identical to the per-iteration values they replace. Measured (300-fact store, dim=1024, median of 30 calls): search() 11.62 -> 1.46 ms/call (8.0x; encode_text 30 -> 1 per call), related() 63.08 -> 16.17 ms/call (3.9x; encode_atom 601 -> 3 per call), probe() 431.93 -> 389.36 ms/call (1.1x; dominated by per-fact content encoding, which is inherent to the algorithm and unchanged). Tests: call-count regression tests for each hoist plus a bit-exact parity test of search() against the pre-fix per-candidate loop.
spfcraze
force-pushed
the
fix/holographic-query-hoist
branch
from
August 1, 2026 12:09
e0be660 to
da9e682
Compare
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.
What does this PR do?
Hoist loop-invariant HRR vector encodes out of FactRetriever hot loops. search() re-encoded the query vector once per candidate (30x redundant work per user message), related() re-encoded both role atoms per fact row (601 encode_atom calls where 3 suffice), and probe() re-encoded the role-content atom per row. All encoders are deterministic (SHA-256 counter blocks), so hoisting is bit-identical.
Related Issue
No direct issue — discovered via code review and reproduced live (see below).
Related PRs reviewed during the duplicate check (none covers this change):
Changes Made
fix/holographic-query-hoist— 2 file(s) changed vs base:plugins/memory/holographic/retrieval.pytests/plugins/memory/test_holographic_retrieval.pyplugins/memory/holographic/retrieval.py: 3 hoists (search query_vec, probe role_content, related role_entity+role_content), ~10 lines moved, zero behavior change. tests/plugins/memory/test_holographic_retrieval.py: +5 tests — encode determinism, call-count regression tests for each hoist (search: encode_text==1; related: role atoms==2; probe: role_content==1), and a bit-exact parity test of search() against the pre-fix per-candidate loop.
How to Test
Measured on a 300-fact store (dim=1024, median of 30 calls, repo venv): search() 11.62 -> 1.46 ms/call (8.0x; encode_text 30 -> 1 per call); related() 63.08 -> 16.17 ms/call (3.9x; encode_atom 601 -> 3 per call); probe() 431.93 -> 389.36 ms/call (1.1x — probe is dominated by per-fact CONTENT encoding, inherent to the algorithm and intentionally unchanged; only its redundant role-atom re-encode was hoisted).
Validation completed (recorded by prp):
tests/plugins/memory/test_holographic_retrieval.py.tests/plugins/memory/: branch 233 passed / 0 failed vs baseline 228 passed / 0 failed — zero branch-only failures.Logs
Sabotage verification output: