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

perf: replace the ipv6 map by an array of struct #20

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

Jorropo
Copy link
Contributor

@Jorropo Jorropo commented Apr 12, 2022

While starting ipfs this package used to take ~20ms while initing:

init github.com/libp2p/go-libp2p-asn-util @21 ms, 20 ms clock, 2623128 bytes, 892 allocs

That is because the map literal is actually creating a new map and adding entries one by one, which for such big map takes a while.
This PR moves this to a separate goroutine and use a sync.Once to synchronise accesses. Almost completely removing it:

init github.com/libp2p/go-libp2p-asn-util @8.7 ms, 0.002 ms clock, 128 bytes, 3 allocs

Never is this map actually used as a map, the only consumer just iterate over it.
So we can use an array of structs containing k and v instead, this pr make the init 0.005ms.

@Jorropo Jorropo changed the title perf: asynchronously move the ipv6 initialisation perf: asynchronously create the map ipv6 initialisation Apr 12, 2022
@Jorropo Jorropo changed the title perf: asynchronously create the map ipv6 initialisation perf: asynchronously create ipv6CidrToAsnMap Apr 12, 2022
@Jorropo
Copy link
Contributor Author

Jorropo commented Apr 12, 2022

@willscott let's not merge this. I have red the code and this change is overkill.

Never is this map actually used as a map, the only consumer just iterate over it.

So we can use an array of structs containing k and v instead.

@Jorropo Jorropo marked this pull request as draft April 12, 2022 15:59
@Jorropo Jorropo requested a review from willscott April 12, 2022 17:28
@Jorropo Jorropo marked this pull request as ready for review April 12, 2022 17:28
@Jorropo
Copy link
Contributor Author

Jorropo commented Apr 12, 2022

@willscott Update it's now slower 0.005ms instead of 0.002ms however it's 0.005ms of CPU time instead of 0.002ms of wall time and 20ms of CPU time.

@Jorropo Jorropo force-pushed the light-init branch 2 times, most recently from ab33cd3 to 51231b0 Compare April 12, 2022 17:33
generate/main.go Outdated Show resolved Hide resolved
That replace a 20ms spent in init, with 0.005ms.
@Jorropo Jorropo changed the title perf: asynchronously create ipv6CidrToAsnMap perf: replace the ipv6 map by an array of struct Apr 12, 2022
@BigLep BigLep added this to the Best Effort Track milestone Apr 21, 2022
@aschmahmann aschmahmann merged commit af6fa36 into libp2p:master Apr 21, 2022
@Jorropo Jorropo deleted the light-init branch April 21, 2022 14:53
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.

4 participants