-
Notifications
You must be signed in to change notification settings - Fork 18k
Need for Improvements on Documentation of io.Copy #38436
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
Comments
Thanks. My first reaction is: why does it matter? It's important that we clearly document what I think it would be entirely reasonable to write a blog post about this, maybe even on the Go blog. I'm not sure it has a clear place on the wiki, as I don't know how people would discover it. |
Thanks for the issue.
What unexpected behavior results from the implementation details you describe? How often does a programmer need to understand that level of detail? I don’t really care how I echo Ian’s points as well (posted before I got a chance to send this :). I think a blog post is a good first start, perhaps. |
I think major optimizations like splice, sendfile, etc. should at least be mentioned by name in On more than one occasion I’ve seen stuff like this: https://github.com/inetaf/tcpproxy/blob/b6bb9b5b82524122bcf27291ede32d1517a14ab8/tcpproxy.go#L434 While Brad is intimately familiar with |
I agree that the use of magic methods and the risk of hiding them is a general problem, but I'm not quite sure it's this problem. |
Hey, I've got the point, Thanks @ianlancetaylor @andybons @ericlagergren, when I wrote this issue I thought about some not trivial cases, like if I serve a static file and I have some trouble on my response time, if I know that my application is using these kindle of syscalls I go directly to page cache stats to see the hit ratio. but if I don't know it, I will spend more time to figure that. Now I think that a blog post is a good first start, if you haven't plans to create it on go blog, I can create it on medium and see the effectiveness, we can revisit this issue in future. About the @ericlagergren point, write a mention on TCPConn is a good idea for me, I found some comments which has this kind of approach like: Lines 568 to 570 in dad94e7
Lines 1670 to 1673 in ea1437a
Lines 622 to 624 in cbaa666
And about @ianlancetaylor last comment I really agree with you, magic methods have trade-offs but in this case, I strongly believe it gives a good optimisation with a low cost. and in golang is easy to understand this kind of methods. Thanks ;) |
Would you like to close this issue or repurpose it to discuss the TCPConn comment? |
Hey Guys, Recently I've been studying a lot about system calls and I noticed that The standard library uses many of then to increase performance, like on io.Copy when if Reader is a file, Writer a TCPConn and the OS is linux, freebsd or windows, it uses sendfile or splice. Another example is this issue to be implemented #36817.
But I feel these different paths are not clear enough on documentation. Example:
On io.Copy:
go/src/io/io.go
Lines 363 to 367 in 34e38ac
On net.TCPConn.ReadFrom:
go/src/net/tcpsock.go
Lines 98 to 99 in 34e38ac
If the programmer doesn't read all the code, he never will realize what the code is doing. Like he will never know that his solution isn't copying the file to userspace but it's just sending from page cache to socket.
I would like to know if we can describe these cases on io.Copy comments or create a wiki about this topic? What is the best approach to spread this knowledge?
Thanks a lot :) and it's my first issue on this project, if I've done something wrong let me know ;)
The text was updated successfully, but these errors were encountered: