Skip to content

run_validators memory optmization#2331

Merged
dblock merged 2 commits into
ruby-grape:masterfrom
ericproulx:run_validator_mem_optimization
May 20, 2023
Merged

run_validators memory optmization#2331
dblock merged 2 commits into
ruby-grape:masterfrom
ericproulx:run_validator_mem_optimization

Conversation

@ericproulx

@ericproulx ericproulx commented May 20, 2023

Copy link
Copy Markdown
Contributor

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

grape-bot commented May 20, 2023

Copy link
Copy Markdown
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

dblock commented May 20, 2023

Copy link
Copy Markdown
Member

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