Skip to content
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

feat: Dont make copies of structs for validation #665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

asmfreak
Copy link

This PR fixes a small problem with validation implementation:
Current implementation uses dst.Interface() which returns a value(T), not a pointer(*T) of a struct T. This can be a performance hit on bigger structures as compiler would have to partially copy the struct T. And since validation is performed on each structure, the whole thing would be copied at least N times (where N is the structure depth).

Passing by value also does not play nicely with other (non-reflection based) validation libraries, such as github.com/go-ozzo/ozzo-validation, since validating a structure there can require a method call, which is not possible. Converting an interface{} with value is not an option also - reflect.Value.Addr() is prohibited for Values, created via reflect.ValueOf(v).

@codecov-commenter
Copy link

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

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.59%. Comparing base (abc7083) to head (c510242).

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #665      +/-   ##
==========================================
- Coverage   77.61%   77.59%   -0.03%     
==========================================
  Files          22       22              
  Lines        7953     7959       +6     
==========================================
+ Hits         6173     6176       +3     
- Misses       1362     1364       +2     
- Partials      418      419       +1     

@asmfreak
Copy link
Author

I'm not sure, if the if branch is needed, really. Please advise, I'll modify the code

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.

2 participants