-
Notifications
You must be signed in to change notification settings - Fork 17.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
os: make File.WriteString not allocate #42406
Comments
Problem: There are options: add |
@josharian you are Josh and can make it work perhaps in the compiler by special recognition, if the symbol is a (*os.File).WriteString and its on an architecture that we've audited as won't be mutating bytes, rewrite it :) |
@josharian Permit me to introduce you to the exciting new internal/unsafeheader package. |
Oooooooooooooooooh! |
Change https://golang.org/cl/268020 mentions this issue: |
Instead of alloc+copy to convert the string to a byte slice, do an unsafe conversion. Rely on the kernel not to scribble on the buffer during the write. Fixes golang#42406 Change-Id: I66f4838b43a11bcc3d67bbfa1706726318d55343
[out for review upstream: https://go-review.googlesource.com/c/go/+/268020] Instead of alloc+copy to convert the string to a byte slice, do an unsafe conversion. Rely on the kernel not to scribble on the buffer during the write. Fixes golang#42406 Change-Id: I66f4838b43a11bcc3d67bbfa1706726318d55343
[out for review upstream: https://go-review.googlesource.com/c/go/+/268020] Instead of alloc+copy to convert the string to a byte slice, do an unsafe conversion. Rely on the kernel not to scribble on the buffer during the write. Fixes golang#42406 Change-Id: I66f4838b43a11bcc3d67bbfa1706726318d55343
[out for review upstream: https://go-review.googlesource.com/c/go/+/268020] Instead of alloc+copy to convert the string to a byte slice, do an unsafe conversion. Rely on the kernel not to scribble on the buffer during the write. Fixes golang#42406 Change-Id: I66f4838b43a11bcc3d67bbfa1706726318d55343
This is os.File.WriteString's implementation:
This currently accounts for
10%35% of allocated space in a service I'm maintaining.We should be able to do an unsafe cast of
s
tob
here, and avoid the allocation.Do any kernels modify the bytes during
Write
? Any other reason why we wouldn't be able to do this?cc @bradfitz
The text was updated successfully, but these errors were encountered: