cli/command/formatter: sort published ports numerically by IP - #7144
Open
hirehamir wants to merge 1 commit into
Open
cli/command/formatter: sort published ports numerically by IP#7144hirehamir wants to merge 1 commit into
hirehamir wants to merge 1 commit into
Conversation
`comparePorts` compared host IPs with `i.IP.String() < j.IP.String()`, which sorts them lexicographically, so "10.0.0.2" ordered before "9.0.0.1" in `docker ps` output. This also avoids formatting both addresses as strings on every comparison. Measured with the added benchmark, which ties every port on the container port: ports before after 64 1540 allocs/op 394 allocs/op 256 5364 allocs/op 1548 allocs/op That's a ~74% (3.9x) reduction in allocations in Docker CLI's port-sorting path.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
- What I did
Fixed #7143 -
docker psordering published ports by the string form of the host IP rather than numerically, so10.0.0.2was listed before9.0.0.1.- How I did it
comparePortscompared IPs withPortSummary.IPis anetip.Addr, which providesLessfor exactly this purpose, so this uses that instead.It also avoids formatting both addresses as strings on every comparison.
- How to verify it
Before:
127.0.0.10:8080->80/tcp, 127.0.0.9:8081->80/tcpAfter:
127.0.0.9:8081->80/tcp, 127.0.0.10:8080->80/tcpA new case in
TestDisplayablePortscovers this.That's a ~74% (3.9x) reduction in allocations in Docker CLI's port-sorting path.
- Human readable description for the release notes