-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: should recognize binary package and intrinsify it where possible #16832
Comments
We've tried not to specialize the compiler against "regular" packages in the standard library. Taking regular packages from std and moving them to github or a project's vendor directory should not affect their performance. Sometimes we specialize for special packages (reflect, runtime, maybe even time), but not "encoding/binary". |
I understand the reasoning, but the result of this is, as I understand it, that the binary package is (regarded as) slow and ends up unused, with hand-crafted (sometimes unsafe) code used in its place. |
To be clear, I'm only opposed to special-casing on the (package name, function name) pair alone. It would be acceptable to make the compiler recognize the structure of the function and special-cases on that instead. |
I'm with @bradfitz. |
What about adding a (cached) |
Uh? He wrote:
Anyway, I do wonder how a compiler can reliably match a function as complex as |
Another possibility might be to create a "BinaryReader" and "BinaryWriter" that would be created for objects of a specific type and data with a particular endianness, and used repeatedly afterwards, in the same way that regular expressions can be compiled into matchers. And the obviously easy special case is an obviously easy special case. |
The compiler should recognize calls to binary.Reader and binary.Writer where the byte order and type of
data interface{}
are compile-time constants, and based on that "do the right thing".One candidate for "the right thing" is, for target/source types that contain no padding and for the native byte order, alias a byte slice to the storage, and pass that to the read or write method. Further enhancements could deal with padding and mismatched native/requested byte order.
The text was updated successfully, but these errors were encountered: