perf: improve packets.ReadPacket performance#322
Open
nickajacks1 wants to merge 1 commit into
Open
Conversation
Replace a couple instances of io.CopyN with io.ReadFull to avoid the
former's extra buffer allocations. This gives a surprisingly large
performance boost.
goos: linux
goarch: amd64
pkg: github.com/eclipse/paho.golang/packets
cpu: Intel(R) Core(TM) Ultra 7 165H
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
ReadPacket/small-22 1109.0n ± 2% 575.8n ± 1% -48.08% (p=0.000 n=8)
ReadPacket/large-22 3.395µ ± 1% 1.405µ ± 2% -58.62% (p=0.000 n=8)
geomean 1.940µ 899.3n -53.65%
│ before.txt │ after.txt │
│ B/op │ B/op vs base │
ReadPacket/small-22 2315.0 ± 0% 696.0 ± 0% -69.94% (p=0.000 n=8)
ReadPacket/large-22 8.826Ki ± 0% 2.853Ki ± 0% -67.68% (p=0.000 n=8)
geomean 4.467Ki 1.392Ki -68.83%
│ before.txt │ after.txt │
│ allocs/op │ allocs/op vs base │
ReadPacket/small-22 16.00 ± 0% 13.00 ± 0% -18.75% (p=0.000 n=8)
ReadPacket/large-22 26.00 ± 0% 17.00 ± 0% -34.62% (p=0.000 n=8)
geomean 20.40 14.87 -27.11%
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.
Replace a couple instances of io.CopyN with io.ReadFull to avoid the former's extra buffer allocations. This gives a surprisingly large performance boost.
Testing
Existing tests pass.
Closing issues
closes #320