perf(doc-trainer): skip cross-linking/emotion + inline type in train mode (−42%)#85
Merged
Merged
Conversation
added 2 commits
July 17, 2026 22:12
…train mode cProfile + per-query wall profiling on a 92k-neuron default brain (N=20) showed find_neurons calls at 1.1-1.4 s/q dominated: 96% DB I/O, ~1% Python. Root cause: SDB 3.2.0 planner picks idx_neuron_type and filters content post-index, scanning 40k+ rows per call. Changes (all gated on ctx.skip_conflicts = train mode): - SemanticLinkingStep + CrossMemoryLinkStep: skip (ENRICH adds cross-links post-train). Saves ~90 find_neurons calls/20 chunks. - EmotionStep: skip (doc knowledge has no emotional valence). - find_neurons: inline type as literal (enum-safe) so the planner uses idx_neuron_type composite (IndexScan vs scan+filter). - find_neurons_exact_batch: keep content IN override but inline type literal too. N+1 base default was 4-5x slower (each type+content call = 750ms). Measured on Toni's 92k default brain, N=20 chunks: 6.7 → 3.85 s/chunk (-42%).
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.
Data-driven fix from cProfile + per-query wall profiling on a 92k-neuron default brain.
Root cause
SDB 3.2.0 planner picks
idx_neuron_typeand filters content post-index — scanning 40k+ rows perfind_neuronscall (1.1–1.4 s/q, 96% DB I/O).Changes (gated on
ctx.skip_conflicts= train mode)typeliteral (enum-safe) → planner usesidx_neuron_typecomposite (IndexScan vs scan+filter).content INoverride (4–5× faster than N+1 default on large brains).Measurement
Toni's 92k default brain, N=20: 6.7 → 3.85 s/chunk (−42%). Full train ETA drops from ~27h to ~7h.
Test plan
Verified by
@acidkill