-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Add AppendProtocols for a an allocation free to get the protocols
While looking at Kubo benchmarks, if you are using connection filters you allocate ~200MiB/s in the Protocols code path. This new method allows to give some preallocated memory in a slice, and it will be reused instead of allocating more. ``` goos: linux goarch: amd64 pkg: github.com/multiformats/go-multiaddr cpu: AMD Ryzen 5 3600 6-Core Processor BenchmarkProtocols-12 3779694 312.0 ns/op 640 B/op 1 allocs/op BenchmarkAppendProtocols-12 26105854 43.13 ns/op 0 B/op 0 allocs/op ```
- Loading branch information
Showing
5 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package multiaddr | ||
|
||
// makeSlice is like make([]T, len) but it perform a class size capacity | ||
// extension. In other words, if the allocation gets rounded to a bigger | ||
// allocation class, instead of wasting the unused space it is gonna return it | ||
// as extra capacity. | ||
func makeSlice[T any](len int) []T { | ||
return append([]T(nil), make([]T, len)...) | ||
} |
This file contains 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
This file contains 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