feat: increase RandomCache size from 256 to 4096 bytes#51
Conversation
`random::<N>()` refills a thread-local cache via `PK11_GenerateRandom` (SHA-256 DRBG) each time the cache is exhausted. That can still cause measurable overheads if a lot of random bytes are needed.
There was a problem hiding this comment.
Pull request overview
This PR increases the thread-local RandomCache buffer used by random::<N>() (for N <= 32) to reduce the frequency of calls into NSS (PK11_GenerateRandom) when many small random values are requested.
Changes:
- Increase
RandomCache::SIZEfrom 256 bytes to 4096 bytes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Clean, minimal change — the constant propagates correctly through RandomCache::new(), randomize(), and the thread-local, so correctness is not a concern.
Nit on PR title: the commit message uses perf: (matching the branch name perf/larger-random-cache), but the PR title says feat:. Consider updating the title to perf: for consistency.
Benchmark data: a 16× buffer increase (256 → 4096) is a reasonable trade-off of ~3.75 KB extra thread-local memory per thread for fewer PK11_GenerateRandom calls, but the PR description says the overhead is "measurable" without providing measurements. Adding before/after numbers (even a quick micro-benchmark) would help reviewers judge whether 4096 is the right landing point vs. 1024 or 2048, and give future readers context for why this value was chosen.
|
I'd like to see some evidence of a performance improvement out of this before making the cut. I'd also like to see copilot review a PR without saying "clean", just once. |
random::<N>()refills a thread-local cache viaPK11_GenerateRandom(SHA-256 DRBG) each time the cache is exhausted. That can still cause measurable overheads if a lot of random bytes are needed.