perf: Eliminate double serialization, add SQLite tuning, optimize hot paths
11 isomorphic performance fixes from deep audit (no behavior changes): - Eliminate double serialization: store_payload now accepts pre-serialized bytes (&[u8]) instead of re-serializing from serde_json::Value. Uses Cow<[u8]> for zero-copy when compression is disabled. - Add SQLite cache_size (64MB) and mmap_size (256MB) pragmas - Replace SELECT-then-INSERT label upserts with INSERT...ON CONFLICT RETURNING in both issues.rs and merge_requests.rs - Replace INSERT + SELECT milestone upsert with RETURNING - Use prepare_cached for 5 hot-path queries in extractor.rs - Optimize compute_list_hash: index-sort + incremental SHA-256 instead of clone+sort+join+hash - Pre-allocate embedding float-to-bytes buffer with Vec::with_capacity - Replace RandomState::new() in rand_jitter with atomic counter XOR nanos - Remove redundant per-note payload storage (discussion payload contains all notes already) - Change transform_issue to accept &GitLabIssue (avoids full struct clone) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -172,14 +172,14 @@ pub fn write_prefetched_mr_discussions(
|
||||
let tx = conn.unchecked_transaction()?;
|
||||
|
||||
// Store raw payload
|
||||
let payload_json = serde_json::to_value(&disc.raw)?;
|
||||
let payload_bytes = serde_json::to_vec(&disc.raw)?;
|
||||
let payload_id = Some(store_payload(
|
||||
&tx,
|
||||
StorePayloadOptions {
|
||||
project_id: Some(local_project_id),
|
||||
resource_type: "discussion",
|
||||
gitlab_id: &disc.raw.id,
|
||||
payload: &payload_json,
|
||||
json_bytes: &payload_bytes,
|
||||
compress: config.storage.compress_raw_payloads,
|
||||
},
|
||||
)?);
|
||||
@@ -206,14 +206,14 @@ pub fn write_prefetched_mr_discussions(
|
||||
let note_payload_id = if should_store_payload {
|
||||
let note_data = disc.raw.notes.iter().find(|n| n.id == note.gitlab_id);
|
||||
if let Some(note_data) = note_data {
|
||||
let note_payload_json = serde_json::to_value(note_data)?;
|
||||
let note_payload_bytes = serde_json::to_vec(note_data)?;
|
||||
Some(store_payload(
|
||||
&tx,
|
||||
StorePayloadOptions {
|
||||
project_id: Some(local_project_id),
|
||||
resource_type: "note",
|
||||
gitlab_id: ¬e.gitlab_id.to_string(),
|
||||
payload: ¬e_payload_json,
|
||||
json_bytes: ¬e_payload_bytes,
|
||||
compress: config.storage.compress_raw_payloads,
|
||||
},
|
||||
)?)
|
||||
@@ -388,14 +388,14 @@ async fn ingest_discussions_for_mr(
|
||||
let tx = conn.unchecked_transaction()?;
|
||||
|
||||
// Store raw payload
|
||||
let payload_json = serde_json::to_value(&gitlab_discussion)?;
|
||||
let payload_bytes = serde_json::to_vec(&gitlab_discussion)?;
|
||||
let payload_id = Some(store_payload(
|
||||
&tx,
|
||||
StorePayloadOptions {
|
||||
project_id: Some(local_project_id),
|
||||
resource_type: "discussion",
|
||||
gitlab_id: &gitlab_discussion.id,
|
||||
payload: &payload_json,
|
||||
json_bytes: &payload_bytes,
|
||||
compress: config.storage.compress_raw_payloads,
|
||||
},
|
||||
)?);
|
||||
@@ -429,14 +429,14 @@ async fn ingest_discussions_for_mr(
|
||||
.iter()
|
||||
.find(|n| n.id == note.gitlab_id);
|
||||
if let Some(note_data) = note_data {
|
||||
let note_payload_json = serde_json::to_value(note_data)?;
|
||||
let note_payload_bytes = serde_json::to_vec(note_data)?;
|
||||
Some(store_payload(
|
||||
&tx,
|
||||
StorePayloadOptions {
|
||||
project_id: Some(local_project_id),
|
||||
resource_type: "note",
|
||||
gitlab_id: ¬e.gitlab_id.to_string(),
|
||||
payload: ¬e_payload_json,
|
||||
json_bytes: ¬e_payload_bytes,
|
||||
compress: config.storage.compress_raw_payloads,
|
||||
},
|
||||
)?)
|
||||
|
||||
Reference in New Issue
Block a user