Skip to content

Optimize Extranonce cloning in hot path (Fixes #2076)#2079

Open
therohityadav wants to merge 1 commit intostratum-mining:mainfrom
therohityadav:fix/issue-2076-extranonce-asref
Open

Optimize Extranonce cloning in hot path (Fixes #2076)#2079
therohityadav wants to merge 1 commit intostratum-mining:mainfrom
therohityadav:fix/issue-2076-extranonce-asref

Conversation

@therohityadav
Copy link

Description

This PR addresses issue #2076 by optimizing memory usage during share validation.

Changes

  • Implemented AsRef<[u8]> for the Extranonce struct in sv2/subprotocols/mining/src/lib.rs.
  • Refactored validate_share in sv2/channels-sv2/src/server/extended.rs to use extend_from_slice instead of clone() + extend().

Impact

This optimization removes unnecessary heap allocations on the "hot path" of share validation, improving performance for the mining server.

Verification

  • Ran cargo test -p mining_sv2 (Verified trait implementation)
  • Ran cargo test -p channels_sv2 (Verified share validation logic remains correct)
  • Ran cargo test (Verified all tests pass across the workspace)

- Implemented AsRef for Extranonce struct.
- Refactored validate_share to use extend_from_slice instead of clone and extend.
- This reduces unnecessary allocations during share validation.
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.

1 participant