Skip to content

perf(doc-trainer): skip cross-linking/emotion + inline type in train mode (−42%)#85

Merged
acidkill merged 2 commits into
mainfrom
perf/skip-linking-train-mode-v2
Jul 17, 2026
Merged

perf(doc-trainer): skip cross-linking/emotion + inline type in train mode (−42%)#85
acidkill merged 2 commits into
mainfrom
perf/skip-linking-train-mode-v2

Conversation

@acidkill

Copy link
Copy Markdown
Owner

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_type and filters content post-index — scanning 40k+ rows per find_neurons call (1.1–1.4 s/q, 96% DB I/O).

Changes (gated on ctx.skip_conflicts = train mode)

  • SemanticLinkingStep + CrossMemoryLinkStep: skip (ENRICH adds cross-links post-train). ~90 fewer find_neurons/20 chunks.
  • EmotionStep: skip (doc knowledge has no emotional valence).
  • find_neurons: inline type literal (enum-safe) → planner uses idx_neuron_type composite (IndexScan vs scan+filter).
  • find_neurons_exact_batch: inline type literal; keep content IN override (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

  • ruff check + format clean
  • profiled N=20 on live default brain (cProfile + conn-proxy, data-driven)
  • CI

Verified by

@acidkill

Toni Nowak 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%).
@acidkill
acidkill merged commit 0841578 into main Jul 17, 2026
7 checks passed
@acidkill
acidkill deleted the perf/skip-linking-train-mode-v2 branch July 17, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant