fix: use a Seq rather than a Set to hold TCP magic ByteStrings - #3484
Open
pjfanning wants to merge 1 commit into
Open
fix: use a Seq rather than a Set to hold TCP magic ByteStrings#3484pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
Motivation: apache#3425 introduced a Set as the collection of accepted TCP magic values. Sets default to HashSet, which hashes its members, and hashing a ByteString walks every one of its bytes. Comparing this handful of 4-byte values is better done with a couple of equality checks over a small ordered collection. Modification: Change ArterySettings.Advanced.TcpMagicValues from Set[ByteString] to immutable.Seq[ByteString], built with distinct.toList rather than toSet so the de-duplication the Set provided incidentally is kept, and change the TcpFraming acceptedMagic parameter to match. These were the only two Set[ByteString] in the tree; both are private[pekko] and both arrived in apache#3425. Add ArterySettingsSpec, which did not exist: the tcp-magic parsing added by apache#3425 had no direct test. Result: TcpFraming's magic check on each inbound connection is a small number of ByteString equality comparisons instead of a hashCode over the received bytes. Acceptance order is now the configured order, where the Set left it unspecified; this is consistent with TcpMagic, the outbound magic, already being the first configured value. No other behaviour changes. Tests: - sbt "remote/testOnly org.apache.pekko.remote.artery.ArterySettingsSpec" - 7 tests succeeded, 0 failed - sbt "remote/testOnly org.apache.pekko.remote.artery.tcp.TcpFramingSpec" - 11 tests succeeded, 0 failed, covering the default, custom and legacy AKKA magic paths through the changed contains call - sbt "remote/mimaReportBinaryIssues" - no issues, no filters needed - ArterySettingsSpec pins the configuration order, the de-duplication including after 4-byte truncation, and both require rejections, so the collection type cannot be changed back without a failure. References: Fixes apache#3483, Refs apache#3425
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
#3425 introduced a
Setas the collection of accepted TCP magic values. Sets default toHashSet, which hashes its members, and hashing aByteStringwalks every one of its bytes. Comparing this handful of 4-byte values is better done with a couple of equality checks over a small ordered collection.Modification:
Change
ArterySettings.Advanced.TcpMagicValuesfromSet[ByteString]toimmutable.Seq[ByteString], built withdistinct.toListrather thantoSetso the de-duplication theSetprovided incidentally is kept, and change theTcpFramingacceptedMagicparameter to match. These were the only twoSet[ByteString]in the tree; both areprivate[pekko]and both arrived in #3425.Add
ArterySettingsSpec, which did not exist: thetcp-magicparsing added by #3425 had no direct test.Result:
TcpFraming's magic check on each inbound connection is a small number ofByteStringequality comparisons instead of ahashCodeover the received bytes.One semantic change worth calling out: acceptance order is now the configured order, where the
Setleft it unspecified. This is consistent withTcpMagic, the outbound magic, already being the first configured value. No other behaviour changes.Tests:
sbt "remote/testOnly org.apache.pekko.remote.artery.ArterySettingsSpec"- 7 tests succeeded, 0 failedsbt "remote/testOnly org.apache.pekko.remote.artery.tcp.TcpFramingSpec"- 11 tests succeeded, 0 failed, covering the default, custom and legacyAKKAmagic paths through the changedcontainscallsbt "remote/mimaReportBinaryIssues"- no issues, no filters neededArterySettingsSpecpins the configuration order, the de-duplication including after 4-byte truncation, and bothrequirerejections, so the collection type cannot be changed back without a failure.References:
Fixes #3483, Refs #3425
Still to follow: a backport to 1.7.x, since #3425 is in 1.7.0 and that branch does not have the faster
ByteString.equalsfrom main.