sourcegraph/internal/byteutils
Erik Seliger 211d5430c6
Add linereader helper (#49965)
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
```
2023-03-24 17:39:49 +01:00
..
linereader_test.go Add linereader helper (#49965) 2023-03-24 17:39:49 +01:00
linereader.go Add linereader helper (#49965) 2023-03-24 17:39:49 +01:00