Skip to content

perf: batch tombstone writes (C4) + structured batch DELETE (B3) - #369

Merged
MPCoreDeveloper merged 3 commits into
masterfrom
perf/b3c4-dml
Sep 3, 2026
Merged

perf: batch tombstone writes (C4) + structured batch DELETE (B3)#369
MPCoreDeveloper merged 3 commits into
masterfrom
perf/b3c4-dml

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

Stack

Inhoud (twee commits)

C4 — a862757a batch-tombstones met evict-dedup

  • IStorage.TombstoneRecords(path, offsets) (default = per-offset TombstoneRecord); Storage-implementatie schrijft de negatieve-prefix-markers over één gecachete read-handle en evict per page één keer i.p.v. per rij.
  • Zowel de commit-path (ApplyBufferedTombstones) als de directe non-transactionele deletes (Table.TombstoneDeletedPositions) lopen via de batch-API; offsets die geen fysiek record zijn (EOF / al gemarkeerd) worden veilig overgeslagen.

B3 — 78d21ea1 structured batch-DELETE (geen dubbele parse)

  • TryParseDeleteForBatch retourneert ook de canonieke WHERE-column + ruwe literal; ExecuteBatchSQL groepeert (where, column, literal).
  • Nieuw Table.DeleteMultipleKeys spiegel DeleteMultiple (contiguous-FW-gate → PK-fast-path → hash-fast-path → generieke fallback) maar resolve keys direct uit de voorgeparste waarden; de col = literal-string en de tweede TryParseSimpleWhereClause worden alleen gebouwd als een generieke fallback écht nodig is.
  • Niet-canonieke statements behouden de string-path (mixed tables bouwen alleen op de zeldzame path).

Meting (Release, 10K deletes op ~100K rijen; median van 3 runs)

Harness #368 (commit-time) deze branch (C4+B3)
comparative SQL DELETE ~41K ops/s ~42K ops/s (mediane 40,1 / 42,0 / 42,5)
comparative Direct DELETE ~58K ops/s ~57K ops/s (mediane 51,6 / 56,6 / 60,0)
--pk legacy / fixed-width 62K / 78K ops/s 65K / 82K ops/s

Conclusie: functioneel neutraal binnen run-ruis (±10%). De wijzigingen zijn veilig (full suite groen) en verminderen allocaties (B3) en page-cache-evicts + handle-gebruik (C4) — pas bij grotere tabellen/allocatie-gevoelige workloads zichtbaar. De volgende echte hefboom blijft B1 (key-only deletes zonder per-rij engine.Read + volledige rij-deserialisatie).

Validatie

  • SharpCoreDB.Tests full suite (Debug) + Release/CI-filter op alle vier de suites (incl. VectorSearch/EFCore/Linq2DB): EXIT=0.

MPCoreDeveloper added 3 commits September 3, 2026 20:18
… flush rewrite)

Stap-0 profiling showed batch DELETE (ExecuteBatchSQL wraps every batch in a storage transaction) was NOT using the tombstone path: the rollback-safe deferral only counted _pendingLogicalDeletes, so db.Flush() still ran the #366 full-file CompactPendingDeletes rewrite (~0.5-0.7s; DELETE stuck at ~12-16K ops/s).

- IStorage.BufferTombstoneForCommit (default no-op) + Storage implementation: buffered offsets per file, applied as in-place negative-prefix markers by ApplyBufferedTombstones() inside FlushBufferedAppendsAndOverwrites() (the commit path) AFTER buffered appends are on disk; rollback discards the buffer via ClearBufferedAppends().

- DeleteRecordsCore + the contiguous FW bulk path now buffer the deleted offsets when IsInTransaction instead of incrementing _pendingLogicalDeletes, so the flush-time full-file rewrite is off the batch-DELETE path entirely.

- Regression: batch DELETE survives reopen even WITHOUT an explicit Flush after ExecuteBatchSQL (commit already tombstoned the rows).

Measured (same machine, Release, comparative harness DELETE 10K of ~100K rows): SQL 0.82s/12K -> 0.24s/41K ops/s, Direct 0.63s/16K -> 0.17s/58K ops/s; --pk legacy 0.16s/62K, fixed-width 0.13s/78K ops/s. Full suite EXIT=0.
- IStorage.TombstoneRecords (default loops TombstoneRecord); Storage batches the in-place negative-prefix markers over one cached read handle and evicts each affected page-cache page once instead of once per row.

- ApplyBufferedTombstones (commit path) and Table.TombstoneDeletedPositions (direct non-transactional deletes) route through the batch API; offsets that are not physical records (EOF/already-marked) are skipped safely.
…parse (B3)

- TryParseDeleteForBatch now also returns the canonical WHERE column + raw literal; ExecuteBatchSQL groups (where, column, literal) instead of plain WHERE strings.

- Table.DeleteMultipleKeys mirrors DeleteMultiple (contiguous-FW gate -> PK fast path -> hash fast path -> generic fallback) but resolves keys directly from the pre-parsed column/literal; the 'col = literal' string and the second TryParseSimpleWhereClause pass are built only when a generic fallback actually runs.

- Non-canonical statements keep the string path (mixed tables rebuild on the rare path).
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
12.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@MPCoreDeveloper
MPCoreDeveloper changed the base branch from perf/commit-time-tombstones to master September 3, 2026 19:35
@MPCoreDeveloper
MPCoreDeveloper merged commit 13a4c15 into master Sep 3, 2026
1 of 2 checks passed
@MPCoreDeveloper
MPCoreDeveloper deleted the perf/b3c4-dml branch September 3, 2026 19:41
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