Skip to content

feat: Dont make copies of structs for validation #737

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

Merged
merged 2 commits into from
May 23, 2025

Conversation

shuheiktgw
Copy link
Collaborator

Following this comment, I took over the original PR and updated it.

Before submitting your PR, please confirm the following.

  • Describe the purpose for which you created this PR.
  • Create test code that corresponds to the modification

@codecov-commenter
Copy link

codecov-commenter commented May 17, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.94%. Comparing base (500180b) to head (69ce48c).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #737   +/-   ##
=======================================
  Coverage   77.94%   77.94%           
=======================================
  Files          22       22           
  Lines        7998     7998           
=======================================
  Hits         6234     6234           
  Misses       1349     1349           
  Partials      415      415           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shuheiktgw shuheiktgw force-pushed the add-pointer-validation-v2 branch from b6dea53 to 69ce48c Compare May 17, 2025 09:39
@@ -1442,7 +1442,7 @@ func (d *Decoder) decodeStruct(ctx context.Context, dst reflect.Value, src ast.N
}

if d.validator != nil {
if err := d.validator.Struct(dst.Interface()); err != nil {
if err := d.validator.Struct(dst.Addr().Interface()); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dst is guaranteed to be addressable. See this line.

@shuheiktgw shuheiktgw requested a review from Copilot May 17, 2025 09:40
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the struct validation process by passing a pointer to the validator instead of a value, preventing unnecessary copying of structs.

  • Changed the validator call from using dst.Interface() to dst.Addr().Interface()
  • Improves efficiency by avoiding struct copies in validation
Comments suppressed due to low confidence (1)

decode.go:1445

  • Consider verifying that 'dst' is addressable before calling .Addr(), to ensure that this change does not lead to runtime panics when 'dst' is not addressable.
if err := d.validator.Struct(dst.Addr().Interface()); err != nil {

@asmfreak
Copy link
Contributor

asmfreak commented May 18, 2025

Thanks! You can close my original PR #665

@goccy
Copy link
Owner

goccy commented May 23, 2025

LGTM 👍

@goccy goccy merged commit 04f9bb5 into master May 23, 2025
25 checks passed
@goccy goccy deleted the add-pointer-validation-v2 branch May 23, 2025 02:02
shuheiktgw added a commit that referenced this pull request Jun 20, 2025
goccy pushed a commit that referenced this pull request Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants