Skip to content

Moving mutex to partition level #5486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

vlntb
Copy link
Collaborator

@vlntb vlntb commented Jun 11, 2025

High Level Overview of Change

This change introduces two key optimizations:

  1. Mutex scope reduction — Limits the lock to individual partitions within TaggedCache, reducing contention (see attached diagram illustrating the current bottleneck).
  2. Decoupling — Removes tight coupling between LedgerHistory and TaggedCache, improving modularity and testability.

Lock Contention analysis based on eBPF shows significant improvements:

  • 🔒 Held Mean Time: ↓ 60.17%
  • ⏱ Held Max Time: ↓ 55.42%
  • 🕒 Wait Mean Time: ↓ 38.74%
  • ⚠️ Wait Max Time: ↑ 5.69%

rippled_ tree, cache, shamap - TaggedCache-3

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@vlntb vlntb marked this pull request as ready for review July 3, 2025 16:23
@vlntb vlntb requested a review from a team as a code owner July 3, 2025 16:23
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

Attention: Patch coverage is 78.26087% with 15 lines in your changes missing coverage. Please review.

Project coverage is 78.4%. Comparing base (7ff4f79) to head (8e47907).

Files with missing lines Patch % Lines
include/xrpl/basics/TaggedCache.ipp 79.0% 13 Missing ⚠️
src/xrpld/app/ledger/LedgerHistory.cpp 33.3% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5486     +/-   ##
=========================================
- Coverage     78.4%   78.4%   -0.1%     
=========================================
  Files          816     816             
  Lines        71715   71678     -37     
  Branches      8577    8600     +23     
=========================================
- Hits         56250   56183     -67     
- Misses       15465   15495     +30     
Files with missing lines Coverage Δ
include/xrpl/basics/SHAMapHash.h 93.5% <ø> (ø)
include/xrpl/basics/TaggedCache.h 100.0% <ø> (ø)
include/xrpl/basics/partitioned_unordered_map.h 98.8% <100.0%> (-0.3%) ⬇️
src/xrpld/app/ledger/LedgerHistory.h 40.0% <ø> (ø)
src/xrpld/app/ledger/LedgerHistory.cpp 50.7% <33.3%> (-1.4%) ⬇️
include/xrpl/basics/TaggedCache.ipp 84.6% <79.0%> (-1.0%) ⬇️

... and 7 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vlntb
Copy link
Collaborator Author

vlntb commented Jul 23, 2025

This branch was tested with Antithesis, and no regressions were found.

@vlntb vlntb removed the request for review from a team July 23, 2025 10:06
@vlntb vlntb marked this pull request as draft July 23, 2025 10:11
@vlntb vlntb marked this pull request as ready for review July 23, 2025 10:12
@bthomee bthomee requested review from a1q123456 and vvysokikh1 July 25, 2025 15:25
@@ -153,8 +158,7 @@ TaggedCache<
KeyEqual,
Mutex>::getTrackSize() const
{
std::lock_guard lock(m_mutex);
return m_cache.size();
return size();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to return 0 here?

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