mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 19:21:50 +00:00
This adds a new helper to read byte slices line by line without the overhead of requiring 24 bytes per subslice it creates from `bytes.Split`. This is also different to bufio.Scanner in that it doesn't need to allocate a large buffer to support long line lengths. I've added a bunch of benchmarks for this, it seems to perform generally better, with fewer allocated memory. In a follow-up PR, I will make use of this helper. ``` goos: darwin goarch: arm64 pkg: github.com/sourcegraph/sourcegraph/internal/byteutils BenchmarkNewLineReader-10 12786025 87.10 ns/op 0 B/op 0 allocs/op BenchmarkBytesSplit-10 9051704 125.6 ns/op 176 B/op 1 allocs/op BenchmarkNewLineReaderLongLine-10 689241 1673 ns/op 0 B/op 0 allocs/op BenchmarkBytesSplitLongLine-10 518218 2198 ns/op 24 B/op 1 allocs/op BenchmarkNewLineReaderManyLines-10 8460 137936 ns/op 0 B/op 0 allocs/op BenchmarkBytesSplitManyLines-10 7690 149148 ns/op 245760 B/op 1 allocs/op PASS ``` |
||
|---|---|---|
| .. | ||
| linereader_test.go | ||
| linereader.go | ||