From 5429595fb9349dadbee716745f7fc8325414c178 Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Mon, 21 Sep 2026 13:32:47 +0100 Subject: [PATCH] perf: Raise the sweep worker cap to 8 A cap of 4 measured slower than the uncapped sweep on 8-core hosts, so raise the cap to 8 and take the question of the right value to review. Trim the sweep comments to the fact and its consequence. --- include/xrpl/basics/TaggedCache.h | 25 ++++++++++-------------- include/xrpl/basics/TaggedCache.ipp | 6 ++---- src/tests/libxrpl/basics/TaggedCache.cpp | 4 ++-- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/include/xrpl/basics/TaggedCache.h b/include/xrpl/basics/TaggedCache.h index 366c411104..fef484bd33 100644 --- a/include/xrpl/basics/TaggedCache.h +++ b/include/xrpl/basics/TaggedCache.h @@ -75,12 +75,10 @@ public: /** * Most worker threads a single sweep() may start. * - * The cache is split into partitions and sweep() shares them out over its - * workers. A worker takes several partitions when there are more of them - * than this, so the thread count is fixed however many partitions the - * cache holds and however many cores the host has. + * A worker takes several partitions when there are more than this, so the + * thread count does not follow the host's core count. */ - static constexpr std::size_t kMaxSweepThreads = 4; + static constexpr std::size_t kMaxSweepThreads = 8; public: TaggedCache( @@ -370,12 +368,11 @@ private: * Sweeps one partition of a key/value cache, in the calling thread. * * @param whenExpire Entries last accessed at or before this point expire. - * @param now Current time, used to pull back a timestamp set in the future. + * @param now Current time, used to pull back a future timestamp. * @param partition The one partition to walk. - * @param stuffToSweep Collects the evicted pointers so the caller can - * destroy them once it has released the cache lock. - * @param allRemovals Accumulates this partition's removal count across all - * workers. + * @param stuffToSweep Collects evicted pointers, destroyed once the caller + * releases the cache lock. + * @param allRemovals Accumulates removals across all workers. */ void sweepPartition( @@ -389,14 +386,12 @@ private: /** * Sweeps one partition of a key-only cache, in the calling thread. * - * A key-only cache owns no pointers, so nothing is collected for later - * destruction and the stuffToSweep parameter is unused. + * A key-only cache owns no pointers, so stuffToSweep is unused. * * @param whenExpire Entries last accessed at or before this point expire. - * @param now Current time, used to pull back a timestamp set in the future. + * @param now Current time, used to pull back a future timestamp. * @param partition The one partition to walk. - * @param allRemovals Accumulates this partition's removal count across all - * workers. + * @param allRemovals Accumulates removals across all workers. */ void sweepPartition( diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index 7489fe051e..f63e1eba4b 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -262,10 +262,8 @@ TaggedCache workers; diff --git a/src/tests/libxrpl/basics/TaggedCache.cpp b/src/tests/libxrpl/basics/TaggedCache.cpp index 639fc84144..d25ec5d53e 100644 --- a/src/tests/libxrpl/basics/TaggedCache.cpp +++ b/src/tests/libxrpl/basics/TaggedCache.cpp @@ -248,9 +248,9 @@ TEST(TaggedCacheTest, sweep_thread_count_is_capped) { using Cache = TaggedCache; - // sweep() runs one worker per partition unless it is capped, and the + // Without the cap, sweep() runs one worker per partition, and the // partition count follows the host's core count. - EXPECT_EQ(Cache::kMaxSweepThreads, 4u); + EXPECT_EQ(Cache::kMaxSweepThreads, 8u); } TEST(TaggedCacheTest, sweep_evicts_from_every_partition)