Repository navigation
Description
Problem
The ~250 ms/result semantic-search slope reported against a live install was not reproduced in-process, and the per-result store work is three orders of magnitude too small to explain it. The N+1 loops that work removed were real and worth removing, but they were not the reported cost. The cause is still unidentified.
What was measured
Release build, 32k seeded text nodes (one paragraph + one 768-dim chunk each), best of 3, through SqliteStore::search_embeddings:
--limit |
before | after |
|---|---|---|
| 1 | 27.57 ms | 27.31 ms |
| 5 | 28.00 ms | 27.96 ms |
| 20 | 30.16 ms | 30.18 ms |
| 50 | 36.71 ms | 36.27 ms |
Flat before the change, flat after. The old serial path measured directly: 30.16 ms serial vs 31.91 ms batched at limit 20 — indistinguishable. Against a reported 0.32 s → 5.03 s.
Per-result costs measured individually: serial re-fetch 0.007 ms/result; get_related_nodes 0.01 ms; get_subtree_data 6.4 ms — the only substantial one, but capped by include_markdown and the CLI path passes include_markdown: 0, so it is inert there.
What the harness did not exercise
- gRPC/socket transport (measurements were in-process)
- Real
generate_embeddingon a loaded model - A real corpus's content and embedding distribution
- Cold state / first-call-after-start
- Concurrent load on a shared daemon runtime
Each was checked against a per-result slope and none scale with result count — embedding generation is per-call, and the CLI handler (packages/daemon/src/services/node_service.rs:543) hard-codes include_markdown: Some(0) and leaves graph_boost/include_edges unset.
Strongest candidate
packages/core/src/services/embedding_service.rs:660 calls nlp_engine.generate_embedding() — a blocking call directly inside an async fn, with no spawn_blocking anywhere in that file. The comment above it acknowledges the blocking ("so do before spawning parallel tasks") but treats it as a local ordering concern.
On a live daemon sharing a tokio runtime, a blocking call on a reactor thread stalls that worker and can serialize otherwise-concurrent work. An in-process, single-threaded, best-of-3 benchmark would never surface it. This does not obviously produce a per-result slope on its own, which is why it is a lead rather than a diagnosis.
Acceptance criteria
- Reproduce the reported slope against a live daemon via the CLI, not in-process — or establish that it does not reproduce there either, and record the install/version/corpus that produced the original numbers
- If it reproduces, attribute it using the per-phase instrumentation now on the search path (
embed_ms/knn_ms/bm25_ms/search_ms/tier3_hydrate_ms/total_ms) - Assess whether
generate_embeddingshould move tospawn_blocking, and whether any other blocking call sits on the runtime - Re-measure the 1/2/5/10/20/50 series on the live path and record it with the build profile stated
Context
Split out of #2399 so the unexplained remainder is not lost when that issue closes. The per-result work removed there was correct-by-construction cleanup; it did not fix the reported symptom, and this issue tracks the symptom.
Activity
Address review: drop the timing tests that cannot fail
Remove the per-result work from the search path (#2452)
mstomar125 commentedon Sep 9, 2026
Live-daemon reproduction attempt — does NOT reproduce, even under artificial stress
Ran this against a genuinely real setup, not another in-process benchmark: a release-build daemon (
cargo build --release), the realnomic-embed-text-v1.5.Q8_0.ggufmodel (loaded via Metal on Apple M2 Pro, confirmed via daemon startup logs), a 32k-node corpus (matching the prior in-process benchmark's own scale — one paragraph + one 768-dim embedding pertextnode), served over the real Unix-socket gRPC transport (not in-process), queried through the realnodespace searchCLI. IsolatedNODESPACE_HOME/NODESPACED_SOCKET, no interference with any real install.Corpus seeding methodology (a deliberate, documented choice)
The corpus itself was seeded with synthetic 768-dim vectors via direct
SqliteStorecalls (a newpackages/core/examples/seed_search_corpus.rs, mirroringsearch_result_scaling_test.rs's exact approach) rather than 32k real embedding-model calls — seeding 32k real embeddings would take on the order of hours and wasn't the point: the prior investigation already proved the store layer is flat at this scale with synthetic vectors. What that prior investigation couldn't test is what only a live daemon provides — real gRPC transport and a real (potentially blocking)generate_embedding()call on the query text, which happens once per search request regardless of corpus size. This setup isolates exactly those two previously-untested variables while holding the already-cleared variable (store layer at 32k rows) constant.Result 1:
--limitsweep (1/2/5/10/20/50, best of 3, sequential)Server-side
total_msfrom the per-phase debug log (embed_ms/search_ms/knn_ms/bm25_ms/tier3_hydrate_ms), not wall-clock CLI time:--limit*The daemon applies a real, existing 3x over-fetch multiplier (
search_ops.rs'seffective_limit = limit * 3whenhas_post_filters, which a plain search triggers via!include_archived) — not a bug, just means the actual server-side work scales with 3× the requested--limit. Noted for anyone else reproducing this.Completely flat, same shape as the prior in-process result. ~50ms baseline, growing to ~100ms at 150 effective results — nothing close to a 250ms/result slope. Extrapolated even generously this is roughly 0.3–0.4ms per additional result, not 250ms.
Result 2: cold-start (first call after a fresh daemon start, model just finished loading)
First real call (embed_ms=20, one-time tokenizer/context warmup): 124ms total. Second (warm) call: 99ms total. A genuine but modest ~25ms cold penalty, one-time only — not a per-search or scaling cost.
(An earlier attempt at this measurement was invalid — fired before the embedding model had actually finished loading in the background, so the "search" was rejected with
Status::unavailablebefore reaching any real work. Corrected by waiting for the daemon's own "Shared embedding model loaded" log line before measuring. Flagging this because it's an easy trap for anyone else trying to reproduce cold-start numbers against this daemon.)Result 3: concurrent load (8 simultaneous
nodespace searchprocesses vs. 8 sequential)8 sequential: 761ms total (~95ms/call average). 8 concurrent: 659ms total — not slower, if anything net faster due to parallelism. But per-request server-side attribution during the concurrent burst shows a real, secondary effect:
bm25_msjumped from ~20-36ms (single-request) to 194–225ms, andknn_msfrom ~35-68ms to 95–121ms, whileembed_msstayed at 0 throughout (no evidence of the blocking-generate_embeddinghypothesis manifesting, even under concurrency). Total per-request latency under 8-way concurrent stress topped out at 294–331ms — real contention, plausibly connection-pool pressure (BM25 and KNN each check out their own connection viatokio::join!, so 8 concurrent requests want 16 connections against an 8-reader pool) — but still nowhere near the reported 5030ms, even under artificial stress well beyond what a single-user desktop app's occasional searches would generate.Result 4:
--include-content(the one per-result cost the prior investigation flagged as substantial-but-capped)114ms (limit 5) → 110ms (limit 20) → 144ms (limit 50). Confirms the prior finding: capped at
MAX_INCLUDE_MARKDOWN_RESULTS(5), inert past that, not a scaling cost.Attribution of the "strongest candidate" lead
generate_embedding()'s blocking call insidesemantic_search(embedding_service.rs:660, nospawn_blocking) — measured directly viaembed_msacross every scenario above: 0ms on every warm call, 15-35ms only on a call after the model has just finished loading (one-time context warmup, not per-request), and flat at 0ms even under 8-way concurrent load (no cross-request serialization observed). This lead does not show a measurable effect at the scale tested. Not implementing a speculativespawn_blockingmigration without measured benefit —nlp_engine: Arc<EmbeddingService>inembedding_service.rs:66makes the plumbing straightforward if this ever needs revisiting (cheapArc::cloneinto the blocking closure), but there's nothing here to fix right now.Conclusion
Does not reproduce, on a setup deliberately built to close every gap the prior in-process investigation flagged (real transport, real model, real corpus scale, cold-state, concurrent load,
include_markdownscaling). The one real, attributable secondary finding — connection-pool contention under concurrent search load — is genuine but roughly 15-20x too small in magnitude to be the reported cause, and wouldn't manifest at all under a single user's normal, non-burst search usage.What's still unaccounted for, and would need the original report's own environment to pin down further: this machine is Apple Silicon (M2 Pro) with Metal GPU offload for the embedding model — a CPU-only or lower-end machine could plausibly see a much larger, and possibly per-call-varying, embedding cost; a much larger real corpus (not 32k) could behave differently if SQLite's FTS5/vec index sees a very different access pattern at 10x+ scale; and if the original report's daemon had been running under sustained real production load (many other RPCs, not just search) rather than an idle daemon doing nothing but search, contention could look very different from this isolated test. Also worth checking, if this resurfaces: the exact NodeSpace version and whether the original 0.32s→5.03s numbers came from wall-clock (client-observed, includes network/serialization) or a server-side log — this issue's own baseline never states which.
Investigation code (seed harness, not a product change) sits uncommitted in a scratch worktree — happy to turn it into a permanent bench fixture (
packages/core/examples/seed_search_corpus.rsor similar) if that'd be useful for future re-investigation at a different scale/machine, just say the word.Add a corpus-seeding example for search-latency investigations (#2528)
mstomar125 commentedon Sep 9, 2026
Closing — the acceptance criteria's own framing ("reproduce ... or establish that it does not reproduce there either, and record") is satisfied by the negative result above: a real release daemon, real model, real 32k-node corpus, real gRPC/CLI path, cold-start and 8-way concurrent load all checked, none reproduced the reported slope. Leading hypothesis (blocking
generate_embedding) measured and ruled out rather than assumed. Reopen if the original reporter's environment/corpus/hardware can be identified and reproduced.