Optimize NativeToValue call paths - #1400
Merged
TristonianJones merged 3 commits intoAug 5, 2026
Merged
Conversation
- **Unified `NativeToValue` Dispatch**: Consolidated private `nativeToValue` and `Registry.NativeToValue` into a single authoritative receiver method. `DefaultTypeAdapter` delegates directly to `emptyRegistry.NativeToValue`. - **Reflection & Allocation Reduction**: - Replaced dynamic `.Convert().Interface().(T)` reflection conversions for type aliases with direct zero-allocation primitive getters (`.Int()`, `.Uint()`, `.Float()`, `.Bool()`, `.String()`). - Integrated custom struct descriptor lookups directly into the reflection branch using `reflect.TypeOf(value)` for instant map matching. - Eliminated duplicate `reflect.ValueOf()` instantiations and redundant nil pointer checks across conversion paths. --- | Benchmark Target | `master` Baseline | Refactored Branch | Delta | Allocs / Op | | :--- | :---: | :---: | :---: | :---: | | `proto/TestAllTypes` | 177.0 ns/op | **87.91 ns/op** | 🚀 **+50.3% faster** | 1 alloc | | `nativeStruct/pointer` | 20.59 ns/op | **13.18 ns/op** | 🚀 **+36.0% faster** | 0 allocs | | `nativeStruct/value` | 17.25 ns/op | **13.52 ns/op** | 🚀 **+21.6% faster** | 0 allocs | | `ref.Val/String` | 4.81 ns/op | **2.62 ns/op** | 🚀 **+45.5% faster** | 0 allocs | | `ref.Val/Int` | 3.73 ns/op | **2.69 ns/op** | 🚀 **+27.9% faster** | 0 allocs | | `int/1` | 3.86 ns/op | **2.55 ns/op** | 🚀 **+33.9% faster** | 0 allocs | | `bool/true` | 2.91 ns/op | **2.11 ns/op** | 🚀 **+27.5% faster** | 0 allocs | | Benchmark Target | `master` Baseline | Refactored Branch | Delta | | :--- | :---: | :---: | :---: | | `nested_proto_field` | 141.3 ns/op | **124.7 ns/op** | 🚀 **+11.7% faster** | | `nested_proto_field_with_index` | 577.5 ns/op | **540.6 ns/op** | 🚀 **+6.4% faster** | | `index` | 122.3 ns/op | **108.1 ns/op** | 🚀 **+11.6% faster** | | `index_list_int_uint_type_index` | 42.87 ns/op | **38.22 ns/op** | 🚀 **+10.8% faster** | | `index_cross_type_float_uint` | 264.4 ns/op | **240.0 ns/op** | 🚀 **+9.2% faster** | | `select_subsumed_field` | 14.27 ns/op | **13.05 ns/op** | 🚀 **+8.5% faster** | | `select_custom_pb3_optional_field` | 43.96 ns/op | **41.71 ns/op** | 🚀 **+5.1% faster** | | `complex_qual_vars` | 338.4 ns/op | **323.1 ns/op** | 🚀 **+4.5% faster** |
TristonianJones
force-pushed
the
native-types-opt
branch
from
August 4, 2026 04:33
e4dbae2 to
bd21ce6
Compare
jnthntatum
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Consolidate the
NativeToValuecode blocksMinor code cleanup on
native.goto simplify reflected type handling.Reflected values are always unwrapped to their non-pointer struct value,
simplifying comparisons and logic related to type testing.