Skip to content

x/mobile/bind: byte slice parameter support without copy #12113

@hyangah

Description

@hyangah

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.

@crawshaw

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions