Skip to content

perf: grow the request queue's dedup cache from 8 KiB, keeping every key up to 3.1M - #30

Merged
metalwarrior665 merged 2 commits into
masterfrom
perf/growing-dedup-cache
Nov 18, 2026
Merged

metalwarrior665 merged 2 commits into
masterfrom
perf/growing-dedup-cache

Conversation

@metalwarrior665

Copy link
Copy Markdown
Member

The request queue's add-deduplication cache was a fixed 1M-slot direct-mapped table: 8 MiB from the first add, and keys landing in the same slot replaced each other. It kept 95% of 100k keys, 64% of 1M and 45% of 2M, where the LRU of Crawlee for JS keeps up to 2M requests exactly. A forgotten key costs a backend add when the crawl sees it again.

It is now a hash table of the same 64-bit fingerprints (handled flag in the lowest bit), with linear probing:

  • starts at 8 KiB on the first add, doubles at 3/4 full, placing the keys again from their fingerprints (no keys needed);
  • keeps every key up to about 3.1M (4M slots, 32 MiB), past JS's 2M;
  • past that, a new key replaces the one in its home slot, so the table stays at most 3/4 full and lookups short.

Same crawl pattern on both (add, 4 re-adds, mark handled; release build):

Keys Before: kept, memory After: kept, memory ns/op before → after
10k 99.4%, 8 MiB 100%, 0.12 MiB 293 → 149
100k 95.4%, 8 MiB 100%, 2 MiB 139 → 100
1M 64.4%, 8 MiB 100%, 16 MiB 152 → 165
2M 44.6%, 8 MiB 100%, 32 MiB 177 → 166
3M 33.0%, 8 MiB 100%, 32 MiB 180 → 194

The allowed-differences.md row is rewritten to match, and now describes the two JS caches precisely: which adds fill and read each, and that JS's full keys never report an unseen request as present while fingerprints could (about 2^-63 a lookup).


Generated by Claude Code

…key up to 3.1M

The cache was a fixed 1M-slot direct-mapped table (8 MiB from the first add), so keys that
landed in the same slot replaced each other: it kept 95% of 100k keys, 64% of 1M and 45% of
2M, where the LRU of JS keeps up to 2M exactly. Each forgotten key costs a backend add when it
is seen again.

It is now a hash table of the same 64-bit fingerprints with linear probing. It starts at 8 KiB
on the first add and doubles at 3/4 full, placing the keys again from their fingerprints, up
to 4M slots (32 MiB): every key is kept up to about 3.1M. Past that, a new key replaces the
one in its home slot, so the table stays at most 3/4 full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
…'s type_complexity

master's check job fails on it since #29.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S

Copy link
Copy Markdown
Member Author

The check job failed on clippy's type_complexity in crates/crawlee-core/src/storage/key_value_store.rs:309, which this PR doesn't touch: master has been red on it since #29. b687b2d names the type (LastSaved), so master turns green when this merges.


Generated by Claude Code

@metalwarrior665
metalwarrior665 merged commit ac820f2 into master Nov 18, 2026
7 checks passed
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.

2 participants