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

run_validators memory optmization #2331

Merged
merged 2 commits into from
May 20, 2023

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented May 20, 2023

This PR change the way validator are created before calling validate. run_validators has always created all the validators before calling validate. In a case where an exception is raised and the validator fail_fast? returns true, the remaining validators won't be validate. Thus, we can optimize the validation process by yielding validator instead of creating all of them at first. It's a small memory optimization and maybe it will speed up a little bit any endpoint that has a validator with fail_fast

In the same file, I also replaced some || [] by &.

@grape-bot
Copy link

grape-bot commented May 20, 2023

1 Warning
⚠️ There're library changes, but not tests. That's OK as long as you're refactoring existing code.

Generated by 🚫 Danger

@ericproulx ericproulx requested a review from dblock May 20, 2023 17:25
@dblock
Copy link
Member

dblock commented May 20, 2023

Nice

@dblock dblock merged commit ccd2330 into ruby-grape:master May 20, 2023
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.

3 participants