Skip to content

perf: improve error handling - #2093

Open
florianl wants to merge 1 commit into
mainfrom
perf-errors.Is
Open

perf: improve error handling#2093
florianl wants to merge 1 commit into
mainfrom
perf-errors.Is

Conversation

@florianl

Copy link
Copy Markdown
Contributor

Skip the reflectlite.TypeOf(target).Comparable() call that errors.Is() makes unconditionally on entry. As forwardReader.Read and reverseReader.Read return the io.* errors directly and never wrap them, avoid the costs of reflectlite.TypeOf().

$ benchstat main.txt new.txt 
goos: linux
goarch: amd64
pkg: github.com/cilium/ebpf/perf
cpu: 12th Gen Intel(R) Core(TM) i7-12700H
                 │  main.txt   │           new.txt           │
                 │   sec/op    │   sec/op     vs base        │
ReadRecordEOR-20   8.967n ± 0%   6.527n ± 0%  -27.21% (n=50)

                 │  main.txt  │            new.txt             │
                 │    B/op    │    B/op     vs base            │
ReadRecordEOR-20   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=50) ¹
¹ all samples are equal

                 │  main.txt  │            new.txt             │
                 │ allocs/op  │ allocs/op   vs base            │
ReadRecordEOR-20   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=50) ¹
¹ all samples are equal

Skip the `reflectlite.TypeOf(target).Comparable()` call that `errors.Is()` makes unconditionally on entry.
As `forwardReader.Read` and `reverseReader.Read` return the `io.*` errors directly and never wrap them,
avoid the costs of `reflectlite.TypeOf()`.

Signed-off-by: Florian Lehner <dev@der-flo.net>
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.

1 participant