Repository navigation
Conversation
- Guard util.DbgPrint calls in ValidateLeafRefData, dataNodesResultAtPath, and matchSingleNode with util.IsDebugLibraryEnabled(), and defer util.StripModulePrefixesStr(schema.Type.Path) to debug/error paths. - Update util.IsNilOrInvalidValue(v) to inspect v.Kind() directly rather than calling IsValueNil(v.Interface()), avoiding heap-boxing of structs, enums, and scalar values on every check. - Add zero-allocation type-switch fast paths in util.DeepEqualDerefPtrs for pointers to primitive scalars and reflect.Value.Equal for comparable values before falling back to reflect.DeepEqual. - Index dereferenced string values into PathQueryResult.StringSet when querying >= 4 string target nodes so matchesNodesResult performs O(1) zero-allocation map lookups.
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.
Summary
This PR reduces CPU and heap allocations during
ytypes.Validateleafref target matching and reflection value checks:ytypes/leafref.go: Checkutil.IsDebugLibraryEnabled()before evaluatingutil.ValueStrDebugarguments and deferutil.StripModulePrefixesStr(schema.Type.Path)to debug or error paths.util.IsNilOrInvalidValue: Inspectv.Kind()(andv.Elem().Kind()for interfaces) directly instead of callingIsValueNil(v.Interface()), eliminating heap allocations (packEface) when checking non-pointer structs, enums, and scalar values during tree walks.util.DeepEqualDerefPtrs: Add a type-switch fast path for pointers to primitive scalars (*string,*uint*,*int*,*bool,*float64) and usereflect.Value.Equalfor comparable values before falling back toreflect.DeepEqual.util.PathQueryResult: PopulateStringSetwhen a path query returns>= 4string or*stringtargets, reducing string leafref validation inmatchesNodesResultfromO(N * M)reflection scans toO(1)map lookups.