perf: fast-path common pointer types in dereferencePointers + inline tag dedup#125
Conversation
…tag dedup - Add type-switch cases for *string, *int, *int64, *uint, *uint64, *float64, *bool in dereferencePointers to avoid reflect.ValueOf for the most common pointer types - Inline tag deduplication in Tags() using a seen map, removing the lo.Uniq pass after accumulation - Add TestSnapshot covering all snapshot merge semantics (13 cases)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #125 +/- ##
==========================================
+ Coverage 89.49% 90.17% +0.67%
==========================================
Files 15 15
Lines 1209 1231 +22
==========================================
+ Hits 1082 1110 +28
+ Misses 102 96 -6
Partials 25 25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR targets lower allocations and faster hot paths in the error metadata pipeline by optimizing pointer dereferencing in KV contexts and tag deduplication, and it adds snapshot-focused tests to validate chain merge semantics.
Changes:
- Add fast-path type-switch cases in
dereferencePointersfor common pointer types to avoid the reflect-based path. - Inline tag deduplication in
OopsError.Tags()during traversal (removing thelo.Uniqpost-pass). - Add
TestSnapshotwith subtests covering scalar precedence, map merges, tag dedup, trace precedence, lazy evaluation, pointer deref, and zero snapshots.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| kv.go | Adds fast-path pointer deref cases before falling back to reflect-based recursion. |
| error.go | Reworks Tags() to deduplicate during accumulation with a seen map. |
| kv_test.go | Adds TestSnapshot to exercise snapshot merge semantics and related behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changes
kv.go: add type-switch cases for*string,*int,*int64,*uint,*uint64,*float64,*boolindereferencePointers— avoidsreflect.ValueOfallocation for the most common pointer types; everything else still falls through to the reflect patherror.go: inline tag deduplication inTags()using aseenmap during accumulation, removing thelo.Uniqpost-passkv_test.go: addTestSnapshotwith 13 sub-tests covering all merge semantics (scalar field precedence, context/userData/tenantData map merging, tag dedup, explicit vs auto trace, lazy evaluation, pointer dereferencing, zero snapshot)