perf: skip reflect.ValueOf in Marshal() for common types#871
Draft
mykaul wants to merge 1 commit intoscylladb:masterfrom
Draft
perf: skip reflect.ValueOf in Marshal() for common types#871mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul wants to merge 1 commit intoscylladb:masterfrom
Conversation
Add a type-switch fast path at the top of Marshal() that skips the reflect.ValueOf pointer-check for common primitive types (and their pointer variants). The sub-marshalers already handle both pointer and non-pointer types via their own type-switches, including nil pointer checks, so the reflect-based dereference+recurse path is unnecessary for these types. Benchmark results (pointer types show the largest improvement since the old path did reflect.ValueOf → Elem().Interface() → recursive Marshal, allocating an extra interface box): *int64: 37ns → 16ns (-57.6%), 2→1 allocs, 16→8 B/op *string: 52ns → 21ns (-59.4%), 2→1 allocs, 32→16 B/op bool: 14ns → 13ns (-5.9%) time.Time: 22ns → 21ns (-6.6%) geomean: -22.6% For a query with 10 pointer parameters, this saves ~300ns and 10 allocations per query execution. Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>
Author
CI Failures — unrelated to this PRBoth failures are known pre-existing flakes:
|
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
Marshal()that skipsreflect.ValueOffor common primitive types and their pointer variantsElem().Interface()Benchmarks
*int64*stringbooltime.TimeFor a query with 10 pointer parameters, this saves ~300ns and 10 allocations per execution.
Risk
Low — falls through to existing reflect path for any type not in the fast-path list. All unit tests pass with
-race.