-
Notifications
You must be signed in to change notification settings - Fork 39.4k
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
Conversion and deep-copy evolution #12598
Comments
Regarding benchmars, there are some simple benchmarks here: |
The main issue with those is that they use types in the api package, and are unlikely to recursively call into Scheme. |
IMO compiler-enforced type safety is a large part of why one would do auto-generated functions in the first place, so I don't agree with this.
Similarly, I don't see the need for this when we already have working errors. There's a cost to generating & catching panics; I don't see a particularly good reason why we should switch. |
Most of this should be outdated now. |
With the introduction of the experimental api prefix, we introduce large amounts of duplicate code for our autogenerated conversions and deep-copy functions. This increases the size of our binaries, and is not elegant. For simplicity, I will only talk about deep-copies, but everything that follows should also apply to conversions. I propose that we eliminate the duplicates as follows:
(In the case of handwritten conversions, we will need to make them switch to using the conversion.Scope instead of calling autogenerated functions directly).
Assuming that we create the deep-copy functions in the order following the import dependency tree, we should not have any duplicate deep-copy functions. However, this approach brings with it some overhead.
For both cleaning up our deep-copy functions and increasing performance in the face of this overhead, I propose we take the following steps:
f(a, b *T) error
, we havef(a, b interface{})
and use type assertions. This lets us reduce the amount of reflection that we use in exchange for boxingIn Go, exception handling is typically discouraged, but it is completely reasonable to use it so long as it doesn't cross an API boundary. For example, here it is used within the standard library. When we see an error during a copy, the copy operation cannot recover. This is the prime use-case for exception handling. We can similarly catch errors within Scheme.DeepCopy, and instead of doing explicit error checking all over the place, simply panic and convert it into an error in DeepCopy. We can also create a new function, MustDeepCopy, which does not catch the error for use within the deep-copy functions.
@wojtek-t @nikhiljindal
The text was updated successfully, but these errors were encountered: