Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: don't allocate in DedupAddrs #2395

Merged
merged 1 commit into from
Jun 27, 2023
Merged

Conversation

marten-seemann
Copy link
Contributor

@marten-seemann marten-seemann commented Jun 27, 2023

Closes #2352.

@marten-seemann marten-seemann linked an issue Jun 27, 2023 that may be closed by this pull request
@marten-seemann marten-seemann changed the title network: don't allocate in DedupAddrs core: don't allocate in DedupAddrs Jun 27, 2023
Copy link
Member

@sukunrt sukunrt left a comment

Choose a reason for hiding this comment

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

This is awesome! 🙇

var addrs []ma.Multiaddr
r := rand.New(rand.NewSource(1234))
for i := 0; i < 100; i++ {
tcpAddr := ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", r.Intn(math.MaxUint16)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sukunrt I tweaked your benchmark function a bit, to make sure the addresses aren't already ordered.

@marten-seemann
Copy link
Contributor Author

Benchmarking result (compared to what we have in master):

name               old time/op    new time/op    delta
DedupAddrs/10-10      396ns ± 1%     178ns ± 2%   -54.93%  (p=0.016 n=4+5)
DedupAddrs/20-10     1.33µs ± 2%    0.62µs ± 0%   -53.35%  (p=0.016 n=4+5)
DedupAddrs/30-10     1.67µs ± 1%    0.92µs ± 1%   -44.70%  (p=0.008 n=5+5)
DedupAddrs/50-10     3.21µs ± 5%    1.85µs ± 3%   -42.30%  (p=0.008 n=5+5)
DedupAddrs/100-10    8.61µs ± 6%    4.92µs ±13%   -42.84%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
DedupAddrs/10-10      88.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
DedupAddrs/20-10      88.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
DedupAddrs/30-10      88.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
DedupAddrs/50-10      88.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
DedupAddrs/100-10     88.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
DedupAddrs/10-10       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
DedupAddrs/20-10       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
DedupAddrs/30-10       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
DedupAddrs/50-10       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
DedupAddrs/100-10      3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)

@marten-seemann marten-seemann merged commit f1236d8 into master Jun 27, 2023
@MarcoPolo MarcoPolo mentioned this pull request Jul 14, 2023
29 tasks
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.

DedupAddrs should not allocate
2 participants