-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
encoding/asn1: remove allocation from init #55973
Comments
Change https://go.dev/cl/435257 mentions this issue: |
No need to file issues for small optimizations, FYI. You can send the CL directly. |
Sure, I will skip Github issue part in minor tasks, thanks. |
The standard library has a few more occurences of this pattern
|
Probably. Note that files in $GOROOT/test should not be changed unnecessarily. Note that files under vendor are copied from upstream sources, and must be changed upstream and then vendored into to the standard library. |
I checked all the code, the memory is allocated on initialization, nowhere else. @ianlancetaylor @andig |
I didn't take care of other cases, as I was mainly focused on reducing init time of common binary. But for the sake of consistency and based on the Ian's comment I will adjust cases below in separate CLs:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
In declaration of types used for reflect, use reflect.TypeOf((*T)).Elem() instead of reflect.TypeOf(T{}) to avoid init-time allocations. See related stdlib issue: golang/go#55973
This comment was marked as off-topic.
This comment was marked as off-topic.
Use reflect.TypeOf((*T)(nil)) instead of reflect.TypeOf(&T{}). See related issue on Go stdlib: golang/go#55973
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sure, I definitely don't object to improving popular libraries. I think this issue should remain open for cases which would directly benefit the standard library, though, as otherwise its scope would be far too broad. |
This comment was marked as off-topic.
This comment was marked as off-topic.
In declaration of types used for reflect, use reflect.TypeOf((*T)).Elem() instead of reflect.TypeOf(T{}) to avoid init-time allocations. See related stdlib issue: golang/go#55973
Use reflect.TypeOf((*T)(nil)) instead of reflect.TypeOf(&T{}). See related issue on Go stdlib: golang/go#55973
Use reflect.TypeOf((*T)(nil)) instead of reflect.TypeOf(&T{}). See related issue on Go stdlib: golang/go#55973
asn1 allocates due to
reflect.TypeOf(new(big.Int))
in init time. We could replace it withreflect.TypeOf((*big.Int)(nil))
.Before:
init encoding/asn1 @1.0 ms, 0.009 ms clock, 224 bytes, 7 allocs
After:
init encoding/asn1 @0.70 ms, 0.002 ms clock, 192 bytes, 6 allocs
The text was updated successfully, but these errors were encountered: