Avoid per-key heap allocation when reconstructing leaf pages from deltas

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Page deltas
    • Storage Engines - Transactions
    • 156.368
    • SE Transactions - 2026-08-14, SE Transactions - 2026-08-28
    • 5

      Summary

      _wt_cell_pack_leaf_kv() (disagg-only, src/include/cell_inline.h) is called once per emitted key when merging leaf page deltas with the base image during a page read (_wti_page_merge_deltas_with_base_image_leaf). For every key it performed:

      1. A heap allocation, copy, and free of the key's non-prefix suffix bytes: the key cell's buffer was a freshly-zeroed WT_ITEM, so __wt_buf_set() allocated a new buffer on every call and __wt_buf_free() released it before returning.
      2. An unconditional full-key copy into last_key, even when prefix compression is disabled and last_key is never read.

      On a page with thousands of entries this means thousands of malloc/free pairs and redundant key copies per single delta page read, on the hottest per-key path of page reconstruction.

      Proposed change

      1. Reference the key suffix in place (key_data + pfx) instead of copying it into an intermediate buffer. The caller's key storage remains valid until __wt_cell_kv_copy() writes the bytes into the new disk image — the same pattern the value cell in this function already uses. This also removes the error-cleanup path (err: label, WT_DECL_RET, __wt_buf_free).
      2. Only snapshot last_key when btree->prefix_compression is enabled, since it is only consumed by __wt_cell_compress_prefix_key(). The guard uses the btree flag rather than s->key_pfx_compress so the first key is still recorded when compression is on.

      Net effect: with prefix compression disabled, delta page reconstruction does zero per-key heap traffic and one fewer full key copy per entry; with it enabled, one allocation/copy/free pair is still eliminated per key.

            Assignee:
            Ravi Giri
            Reporter:
            Ravi Giri
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: