Skip to content

perf(#3183 B1): batch file_data/class_data inserts via executemany - #3186

Merged
squid-protocol merged 1 commit into
mainfrom
perf/3183-serial-tail
Sep 18, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
perf/3183-serial-tail

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Implements B1 of #3183 (batch the file_data/class_data writes) and reports the outcome of investigating B2/B4 (the multi-core tail items), which do not pan out for this workload.

B1 — remove the row-by-row file_data/class_data insert

record_keeper.record_mission inserted file_data one cursor.execute() per row purely to read cursor.lastrowid into path_to_file_id (and class_data likewise for class_id_map). Both are AUTOINCREMENT tables whose next id is (highest-ever id) + 1, tracked in sqlite_sequence and not reset by the idempotent per-commit wipe — so we read that seq once, precompute each row's id, and flush file_data then class_data (FK parents before the existing function/edge child batches) with executemany. executemany auto-assigns ids in list order, reproducing the old per-row ids exactly. This removes the O(N) Python↔SQLite round-trip that grew the serial DB-write with repo size.

Verified byte-identical

PYTHONHASHSEED=0, baseline (origin/main) vs change, on curl:

  • audit.json + sarif.json IDENTICAL
  • master.db: file_data (1060), class_data (764), function_data (6254), edge_data (2518) rows all IDENTICAL (full row dumps compared)

Wall (A-vs-A control, tests/tools/phase_ab.py)

5 rounds on all_language_repo, quiesced box:

engine mean wall Δ vs base
base 15.52s —
base#ctl (noise floor) 15.46s −0.3%
mine (B1) 15.42s −0.6%

Within the control noise band — B1 is wall-neutral at ALR size (byte-identical, zero risk). The DB-write saving is size-proportional and below the measurement floor here; it shows up on much larger repos. audit.json/sarif.json IDENTICAL on ALR too.

B2 / B4 — investigated, not worth shipping

The issue's multi-core items don't clear the byte-identity + benefit bar:

  • B4 (parallel Phase 10): the three audits are separable state-wise, but api_mapper and xray are CPU-bound Python — a ThreadPoolExecutor gives zero speedup (measured serial 2.08s vs threaded 2.10s; the GIL serializes them). Only processes help (fork pool: 2.08s→1.76s, ~0.3s ≈ 2% of wall), but the dominant audit (xray, 1.73s) needs self.config, and ResolvedConfig is not picklable — its __getattr__ infinite-recurses during unpickle (latent bug). Moving it to a worker would require hand-marshalling a config subset (fragile / byte-identity risk) for a ~2% gain that's below box noise. Not worth it as written.
  • B2 (concurrent recorders): unsafe — audit_recorder mutates the shared graph in place (telemetry["control_flow_ratio"]=, file_data["file_impact"]=, file_data.pop("risk_vector")) that the peer recorders read, so running them concurrently races on risk_vector/file_impact → nondeterministic output. The only race-free subset (llm/sarif/sbom) is CPU/GIL-bound, so threading it yields ~nothing.

Net: the serial tail is dominated by GIL-bound Python + SQLite I/O that don't thread-parallelize, and the CPU-bound parts can't cheaply move to processes (unpicklable config / a too-large shared graph to pickle). B1 is the clean, safe win; B3 (overlapped DB writer) remains the only structural lever and stays gated as the issue notes.

Closes the B1 checkbox of #3183.

🤖 Generated with Claude Code

The master.db write inserted file_data one execute() per row purely to
read cursor.lastrowid into path_to_file_id (and class_data likewise for
class_id_map). Both are AUTOINCREMENT tables whose next id is (highest-ever
id)+1, tracked in sqlite_sequence and unaffected by the idempotent per-commit
wipe -- so we anchor to that seq once, precompute each row's id, and flush
file_data then class_data (FK parents before the function/edge child batches)
with executemany. executemany auto-assigns ids in list order, reproducing the
old per-row ids exactly.

Verified byte-identical on curl (PYTHONHASHSEED=0, baseline vs change):
audit.json + sarif.json IDENTICAL; master.db file_data (1060), class_data
(764), function_data (6254), edge_data (2518) rows all IDENTICAL.

Baseline regen: the two pre-existing RUF005 list-concat findings only shifted
line numbers (1346/1459 -> 1329/1492); no new lint.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit ac641c2 into main Sep 18, 2026
29 checks passed
@squid-protocol
squid-protocol deleted the perf/3183-serial-tail branch September 18, 2026 19:40
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