Repository navigation
perf(#3183 B1): batch file_data/class_data inserts via executemany - #3186
Merged
Merged
Conversation
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]>
Contributor
Closed
4 tasks
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.
Implements B1 of #3183 (batch the
file_data/class_datawrites) 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_datainsertrecord_keeper.record_missioninsertedfile_dataonecursor.execute()per row purely to readcursor.lastrowidintopath_to_file_id(andclass_datalikewise forclass_id_map). Both areAUTOINCREMENTtables whose next id is(highest-ever id) + 1, tracked insqlite_sequenceand not reset by the idempotent per-commit wipe — so we read that seq once, precompute each row's id, and flushfile_datathenclass_data(FK parents before the existing function/edge child batches) withexecutemany.executemanyauto-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.jsonIDENTICALmaster.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: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.jsonIDENTICAL on ALR too.B2 / B4 — investigated, not worth shipping
The issue's multi-core items don't clear the byte-identity + benefit bar:
api_mapperandxrayare CPU-bound Python — aThreadPoolExecutorgives 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) needsself.config, andResolvedConfigis 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.audit_recordermutates 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 onrisk_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