-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
When a Go function or method taking a byte slice is called, the current implementation
creates a copy of the arguments and passes it to the Go function. The implementation
was based on the assumption that the Go function is free to keep the slice for later use.
This prevents implementation like io.Read([]byte) where the parameter's content
is modified during call. Moreover, it costs an extra copy & memory which can be significant
depending on the byte slice size.
Instead, I propose to pass a slice backed by the foreign language's byte array if possible.
Users who want to keep the slice for later use have to be aware of the limitation and somehow
create a copy for now.
More discussion on automation or tool support to detect such use cases
(another kind of escape analysis) is welcome.