Skip to content

Investigate and optimize insert_single hot path (77us vs 3.6us pre-hardening) #57

@zvndev

Description

@zvndev

Problem

The insert_single benchmark workload regressed from ~3.6us to ~77us (21x) after the hardening phase (PRs #8 through #29). This is measured with WalSyncMode::Off, so WAL fsync is not the cause.

Key observations

  • Per-row cost improved: insert_batch_1k (which also calls execute_powql once per row) is 8% faster than baseline. The per-row insert cost decreased.
  • Per-call overhead exploded: insert_single measures a single execute_powql("insert User { ... }") call per criterion iteration. The 77us overhead is per-call, not per-row.
  • Baseline: 3,611 ns/iter at commit d44e69b (rustc 1.89.0, ubuntu-24.04)
  • Current: 77,659 ns/iter at commit 9a14c4a (rustc 1.95.0, ubuntu-24.04)

What changed

Between d44e69b and 9a14c4a:

  • PAGE_HEADER_SIZE grew from 8 to 16 bytes (LSN field added)
  • CRC32 checksums on B+tree save/load (but not on in-memory insert)
  • StorageError enum replaced io::Error in many paths
  • Executor was split into submodules (mod.rs, plan_exec.rs, compiled.rs, eval.rs)
  • Various unwrap()expect() changes
  • Bounds checks added to slot directory access

Investigation needed

  • Profile the insert_single benchmark to find where the 70us overhead lives
  • Check if the executor module split affected inlining (LTO should handle this, but criterion bench profile may differ)
  • Check if encode_row_into_with_layout got slower
  • Check if B+tree in-memory insert_int got slower (unlikely — code unchanged)
  • Check if heap page allocation overhead increased with the larger header

Current workaround

The bench baseline has been updated to reflect current performance, and the insert_single_over_btree_lookup thesis ratio ceiling was relaxed from 16x to 300x. This is a tracking issue to restore insert_single to near-baseline performance.

Labels

performance, engine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions