encoding/asn1: use reflect.TypeAssert to improve performance #75825
+10
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use "reflect.TypeAssert" can gain some performance improvements:
goos: darwin
goarch: arm64
pkg: encoding/asn1
cpu: Apple M4
│ old │ new │
│ sec/op │ sec/op vs base │
ObjectIdentifierString-10 51.48n ± 1% 49.72n ± 2% -3.41% (p=0.000 n=10)
Marshal-10 7.549µ ± 0% 7.466µ ± 1% -1.10% (p=0.000 n=10)
Unmarshal-10 1.808µ ± 0% 1.798µ ± 0% -0.58% (p=0.000 n=10)
geomean 889.0n 873.8n -1.70%
ObjectIdentifierString-10 32.00 ± 0% 32.00 ± 0% ~ (p=1.000 n=10) ¹
Marshal-10 7.336Ki ± 0% 7.336Ki ± 0% ~ (p=1.000 n=10) ¹
Unmarshal-10 432.0 ± 0% 432.0 ± 0% ~ (p=1.000 n=10) ¹
geomean 470.0 470.0 +0.00%
¹ all samples are equal
ObjectIdentifierString-10 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=10) ¹
Marshal-10 271.0 ± 0% 271.0 ± 0% ~ (p=1.000 n=10) ¹
Unmarshal-10 24.00 ± 0% 24.00 ± 0% ~ (p=1.000 n=10) ¹
geomean 18.67 18.67 +0.00%
¹ all samples are equal
Updates #62121