-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
copyZeroAlloc allocates when interface uses genericWriteTo #1889
Comments
it doesn't look like the golang zero copy backend works with Lines 2205 to 2211 in 40bdc4a
the func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) {
pfd, network := getPollFDAndNetwork(w)
// TODO(panjf2000): same as File.spliceToFile.
if pfd == nil || !pfd.IsStream || !isUnixOrTCP(string(network)) {
return
} func getPollFDAndNetwork(i any) (*poll.FD, poll.String) {
sc, ok := i.(syscall.Conn)
if !ok {
return nil, ""
} |
From versity#919, This provides the *os.File handle to io.Copy() for the case where the full file range is requested. This prevents hiding the *os.File type for io.Copy() optimizations. This still requires the change to valyala/fasthttp#1889 to expose the net.Conn similarly to enable the linux sendfile optimization.
it looks like go's
io.CopyBuffer
always uses theWriterTo
interface if it's available, much likecopyZeroAlloc
however,
File
andTCPConn
unfortunately have a fallback in theirWriterTo
that callsio.Copy
ifsendfile
isn't possible, which allocates an implicit bufferhttps://github.com/golang/go/blob/15c558016088d6aaf103b4f0fd2b716a4573e5a2/src/net/net.go#L789
https://github.com/golang/go/blob/15c558016088d6aaf103b4f0fd2b716a4573e5a2/src/os/file.go#L274
this is with an
os.File
reachingwriteBodyFixedSize
The text was updated successfully, but these errors were encountered: