Skip to content

perf: improve packets.ReadPacket performance#322

Open
nickajacks1 wants to merge 1 commit into
eclipse-paho:masterfrom
nickajacks1:perf-readpacket
Open

perf: improve packets.ReadPacket performance#322
nickajacks1 wants to merge 1 commit into
eclipse-paho:masterfrom
nickajacks1:perf-readpacket

Conversation

@nickajacks1
Copy link
Copy Markdown
Contributor

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%

Testing

Existing tests pass.

Closing issues

closes #320

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%
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.

Reduce Unnecessary Allocations

1 participant