New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syscall: add array of Errno errors? #30535
Comments
Sounds fine. We've done that elsewhere in std already. |
@josharian I'm curious; is there a reason you're looking into the performance of os/exec recently? |
In some circumstances it was showed up in go-fuzz pprof output. See also dvyukov/go-fuzz#215. |
I started on this and then started to wonder whether we should do this trick in the compiler for small ints in interfaces instead, like we do with single-byte values. We have talked about that in the past and worried about binary size and weird perf cliffs. But this change would add more to binary size, and almost everyone uses syscall, and doing it in the compiler would benefit other code. |
(Note to self; on phone.) A narrower fix would be to add a ByteErrno, applicable only for byte-sized errnos, that delegates to syscall.Errno for errors strings. |
No adding exported stuff to syscall, though. And we can't change the type on people anyway. |
Btw, we already have: https://github.com/golang/go/blob/8f9902d/src/syscall/syscall_unix.go#L139 // errnoErr returns common boxed Errno values, to prevent
// allocations at runtime.
func errnoErr(e Errno) error {
switch e {
case 0:
return nil
case EAGAIN:
return errEAGAIN
case EINVAL:
return errEINVAL
case ENOENT:
return errENOENT
}
return e
} |
... feel free to add to that. Or change its implementation to the array thing. |
I was thinking of it just for this particular use, which never makes it to the outside world. errnoErr is perfect but unexported and in the wrong package. I suppose I could export it and move it to some internal package. |
SGTM |
Change https://golang.org/cl/164971 mentions this issue: |
Running os/exec's new BenchmarkExecEcho on my machine, 8% of allocations are from
internal/poll/fd_poll_runtime.go:45
:return syscall.Errno(errno)
. This allocates when we convert fromsyscall.Errno
to anerror
. (For those who are curious, the errno is 22, EINVAL, indicating that the file is not pollable. We end up noting only that the error is non-nil, atinternal/poll/fd_unix.go:64
, and then dropping it, atos/file_unix.go:157
.)There aren't many errnos. We could avoid this allocation, and others, by adding an array of all expected Errnos as errors in package syscall, and adding an accessor function to return them. Something like:
Note that errnoErrors would be generated by a script, and would be treated as static data by the compiler and linker, so the impact would be only on binary size (not compilation time or process startup).
Package syscall is frozen and sensitive, so I wanted to ask before doing the work.
cc @bradfitz @ianlancetaylor
The text was updated successfully, but these errors were encountered: