-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve performance for "equalFieldType" function #3479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
OLD: ``` Benchmark_equalFieldType-12 3320424 361.0 ns/op 80 B/op 9 allocs/op ``` NEW: ``` Benchmark_equalFieldType-12 12170480 99.85 ns/op 16 B/op 3 allocs/op ```
OLD: ``` Benchmark_equalFieldType-12 3320424 361.0 ns/op 80 B/op 9 allocs/op ``` NEW: ``` Benchmark_equalFieldType-12 11102847 102.2 ns/op 16 B/op 3 allocs/op ``` + solve the problem with passing on the tag name
WalkthroughThis change refactors the data binding logic by updating the function signatures and internal calls to Changes
Sequence Diagram(s)sequenceDiagram
participant Binder as Binder (e.g., FormBinding)
participant formatBindData
participant equalFieldType
participant FieldCache
Binder->>formatBindData: formatBindData(bindingName, out, data, key, value, ...)
formatBindData->>equalFieldType: equalFieldType(out, kind, key, bindingName)
equalFieldType->>FieldCache: Check or build fieldInfo for type+aliasTag
FieldCache-->>equalFieldType: Return field match result
equalFieldType-->>formatBindData: true/false
formatBindData-->>Binder: Assign or skip value
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3479 +/- ##
=======================================
Coverage 84.35% 84.36%
=======================================
Files 120 120
Lines 12190 12215 +25
=======================================
+ Hits 10283 10305 +22
- Misses 1477 1480 +3
Partials 430 430
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:
|
OLD: ``` Benchmark_equalFieldType-12 3320424 361.0 ns/op 80 B/op 9 allocs/op ``` NEW: ``` Benchmark_equalFieldType-12 11102847 102.2 ns/op 16 B/op 3 allocs/op ``` + solve the problem with passing on the tag name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
binder/mapping.go (1)
222-223
: Consider adding test coverage for edge cases.Static analysis indicates several code paths lack test coverage:
- Lines 222-223:
uri
cache case- Line 248: Nested struct field export check
- Lines 263-264: String key map handling
- Lines 279-280: Type assertion failure handling
Would you like me to help generate additional test cases to improve coverage for these edge cases?
Also applies to: 248-248, 263-264, 279-280
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 222-223: binder/mapping.go#L222-L223
Added lines #L222 - L223 were not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
binder/cookie.go
(1 hunks)binder/form.go
(2 hunks)binder/header.go
(1 hunks)binder/mapping.go
(4 hunks)binder/mapping_test.go
(13 hunks)binder/query.go
(1 hunks)binder/resp_header.go
(1 hunks)state_test.go
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
state_test.go (1)
state.go (1)
GetState
(100-110)
binder/mapping_test.go (4)
bind_test.go (3)
User
(1920-1927)User
(2046-2050)User
(2076-2082)binder/form_test.go (4)
User
(25-30)User
(65-69)User
(101-108)User
(205-209)binder/cookie_test.go (2)
User
(22-27)User
(60-64)binder/header_test.go (2)
User
(18-23)User
(60-64)
🪛 GitHub Actions: golangci-lint
state_test.go
[error] 448-448: golangci-lint: directive //nolint:govet // It does not really matter for test
is unused for linter "govet" (nolintlint)
🪛 GitHub Check: codecov/patch
binder/mapping.go
[warning] 222-223: binder/mapping.go#L222-L223
Added lines #L222 - L223 were not covered by tests
[warning] 228-228: binder/mapping.go#L228
Added line #L228 was not covered by tests
[warning] 248-248: binder/mapping.go#L248
Added line #L248 was not covered by tests
[warning] 263-264: binder/mapping.go#L263-L264
Added lines #L263 - L264 were not covered by tests
[warning] 279-280: binder/mapping.go#L279-L280
Added lines #L279 - L280 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: Compare
- GitHub Check: unit (1.24.x, macos-latest)
- GitHub Check: unit (1.23.x, windows-latest)
- GitHub Check: unit (1.24.x, windows-latest)
- GitHub Check: repeated
🔇 Additional comments (13)
state_test.go (2)
451-452
: Reorder and Addname
andkey
Fields intestCase
StructThe
testCase
struct now includesname
andkey
fields, positioned afterexpected
. This aligns with their usage inrunGenericTest
, improving clarity and maintainability. Ensure the struct order matches all literal initializations.
472-473
: Explicit Field Naming in Generic Test CasesAll
testCase
literals inTestState_GetGeneric
have been updated to use named fields (name
,key
,value
,expected
,ok
) instead of positional initialization. This eliminates ordering fragility and makes each test’s intent clear.Also applies to: 477-478, 482-483, 487-488
binder/cookie.go (1)
30-30
: LGTM! Consistent with alias tag awareness refactor.The addition of
b.Name()
as the first argument toformatBindData
aligns with the performance improvement goals mentioned in the PR objectives. This change enables alias tag awareness and caching optimizations.binder/query.go (1)
30-30
: LGTM! Consistent refactor pattern across binder types.The change follows the same pattern as other binder implementations, adding the binding name as the first parameter to enable alias tag awareness and performance optimizations.
binder/form.go (3)
39-39
: LGTM! Consistent with alias tag refactor.The addition of
b.Name()
as the first argument maintains consistency with the performance optimization pattern across all binder types.
58-58
: LGTM! Multipart form values handled consistently.The multipart form value handling is updated with the same pattern, ensuring alias tag awareness is applied uniformly across all form binding scenarios.
66-66
: LGTM! File header handling updated consistently.The file header processing follows the same pattern, completing the consistent refactor across all form binding use cases.
binder/resp_header.go (1)
30-30
: LGTM! Completes consistent refactor across all binder types.The response header binder follows the same pattern as all other binding implementations, ensuring uniform alias tag awareness and performance benefits across the entire binding system.
binder/header.go (1)
29-29
: LGTM!The update correctly passes the binding name to
formatBindData
for alias tag-aware field matching.binder/mapping_test.go (2)
16-49
: Test updates look good!All test function calls have been correctly updated to include the
"query"
alias tag parameter, maintaining consistency with the refactored function signatures.Also applies to: 202-341
347-364
: Great addition of the benchmark!The benchmark effectively tests the performance of the new caching mechanism in
equalFieldType
with realistic scenarios including nested struct fields.binder/mapping.go (2)
179-196
: Helper functions are well-implemented!The
isStringKeyMap
,isExported
, andfieldName
functions provide clean abstractions for the refactored logic.
258-290
: Excellent performance optimization with caching!The refactored
equalFieldType
function with caching and alias tag support aligns perfectly with the PR's performance improvement goals. The benchmark results in the PR description show ~3.6x speedup.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 263-264: binder/mapping.go#L263-L264
Added lines #L263 - L264 were not covered by tests
[warning] 279-280: binder/mapping.go#L279-L280
Added lines #L279 - L280 were not covered by tests
OLD:
NEW:
+ solve the problem with passing on the tag name