Skip to content

Concurrent lookups in an encrypted dictionary pack read by range contend in the leaflet cache #2146

Open

Description

@bplatz

Found while fixing #2130's review: on encrypted local storage, lookups in a forward dictionary pack that is read by range slow down sharply as threads are added.

A pack is read by range until it is promoted into the dictionary allowance, and for good if it is larger than the allowance or the working set doesn't fit. Each lookup reads its two offsets and its value through the leaflet cache's decrypted segments (CachedUnits::extend_into → LeafletCache::try_get_or_load_source_unit).

Wall time per lookup per thread, one pack, dev-fast, on a laptop:

threads read by range promoted (for comparison)
1 160–230 ns 10 ns
2 350–430 ns 10 ns
4 670–1,050 ns 11 ns
8 2,700–2,900 ns 11 ns
10 3,600–4,200 ns 12 ns

Not profiled yet. The likely cost is that every segment read is a moka get on a key all threads share: it clones the segment's Arc<[u8]>, which writes its reference count, and records a read op. A miss also updates the pack's MissMeter.

UnitMemoScope serves repeated segments from a thread-local memo, but only the result formatters open it. Decode loops elsewhere (filters, ORDER BY and GROUP BY over strings) take the shared path on every lookup.

When it matters: concurrent queries over an encrypted store while packs warm up, and in steady state when the working set is larger than the allowance or a pack is larger than it. On next, an encrypted pack was decrypted whole, so these lookups didn't contend, at the memory cost #2130 removes.

Directions, to be chosen after a profile:

  • Open UnitMemoScope around the remaining per-row decode loops.
  • Read a cached segment without cloning its Arc under concurrency.

Acceptance: lookups by range on 8 threads stay within a small factor of one thread, pinned by a test like lookups_in_a_promoted_pack_scale_across_threads (dict/pack_reader.rs).

Activity

  1. added
    P2
    area:storage
    performance
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:storageperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions