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

avoid allocation in Validator.All.contramap #3555

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

fwbrasil
Copy link
Contributor

Problem

Tapir uses a default Validatator.All instance with an empty validator sequence and calls contramap on each request handling as part of the value decoding (the call comes from Schema.map)

Solution

Cast the current instance and return it instead of allocating a new one.

Notes

  • This is part of Reduce allocation rate #3552
  • The cast seems safe since the class is immutable and the empty sequence should have the same behavior regardless of the type parameter.

@adamw adamw merged commit a809aca into softwaremill:master Feb 29, 2024
23 checks passed
@adamw
Copy link
Member

adamw commented Feb 29, 2024

Thanks!

@fwbrasil fwbrasil deleted the opt-validator-empty-contramap branch February 29, 2024 21:54
goawash pushed a commit to goawash/tapir that referenced this pull request Mar 13, 2024
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