Skip to content

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Apr 4, 2025

PR description

EthProtocol.requestIdCompatible is called for every p2p message, and in the previous implementation it was allocating a new Set every time, but since the data in the set does not change, it can be created once, moreover to avoid (un)boxing from and to int and hashes, using a BitSet optimize the lookup.

Fixed Issue(s)

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 marked this pull request as draft April 4, 2025 15:24
@fab-10 fab-10 marked this pull request as ready for review April 4, 2025 15:30
.contains(code);
EthProtocolMessages.RECEIPTS);
REQUEST_ID_MESSAGES =
new BitSet(requestIdMessages.stream().mapToInt(i -> i).max().getAsInt() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this more optimal than just getting the size of the set?

Copy link
Contributor

@ahamlat ahamlat Apr 8, 2025

Choose a reason for hiding this comment

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

We can make it even constant, like 64 which is the size of a long (64 bits), if we want to  decouple it from requestIdMessages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the requestIdMessage is the index of the bitset, so the bitset should be large enough for the message with the largest index, since bitset starts from 0 then the optimal size is max index + 1, not sure what do you mean by decoupling?
Then I plan to make EthProtocolMessages an enum, so we can directly use EnumSet that is clearer.

.contains(code);
EthProtocolMessages.RECEIPTS);
REQUEST_ID_MESSAGES =
new BitSet(requestIdMessages.stream().mapToInt(i -> i).max().getAsInt() + 1);
Copy link
Contributor

@ahamlat ahamlat Apr 8, 2025

Choose a reason for hiding this comment

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

We can make it even constant, like 64 which is the size of a long (64 bits), if we want to  decouple it from requestIdMessages.

@fab-10 fab-10 enabled auto-merge (squash) April 9, 2025 10:55
@fab-10 fab-10 merged commit d86e86f into hyperledger:main Apr 9, 2025
43 checks passed
@fab-10 fab-10 deleted the eth-protocol-message-opt branch April 9, 2025 12:29
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