Skip to content

Don't take a global lock per hash in ShortHash. - #5360

Merged
dmkozh merged 1 commit into
stellar:masterfrom
dmkozh:hash_opt
Jul 22, 2026
Merged

dmkozh merged 1 commit into
stellar:masterfrom
dmkozh:hash_opt

Conversation

@dmkozh

@dmkozh dmkozh commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Don't take a global lock per hash in ShortHash.

Locking was only used for a test-only assertion, and even for that it can be replaced with a simple atomic. This change removes unnecessary contention between compute threads.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

Copilot AI review requested due to automatic review settings July 22, 2026 18:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes per-hash locking while retaining test-only reseeding safeguards.

Changes:

  • Removes the global mutex from short-hash operations.
  • Uses an atomic flag for test-only hash tracking.
  • Restricts test-related APIs with BUILD_TESTS.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/crypto/ShortHash.h Adjusts test-only API declarations.
src/crypto/ShortHash.cpp Removes locking and adds atomic test tracking.

Comment thread src/crypto/ShortHash.h Resolved
Locking was only used for a test-only assertion, and even for that it can be replaced with a simple atomic. This change removes unnecessary contention between compute threads.

@graydon graydon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@dmkozh
dmkozh added this pull request to the merge queue Jul 22, 2026
Merged via the queue into stellar:master with commit 6936b09 Jul 22, 2026
54 checks passed
@dmkozh
dmkozh deleted the hash_opt branch July 22, 2026 23:23
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.

3 participants