-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
perf(common): lazy load class validator and class transformer #11676
Conversation
Pull Request Test Coverage Report for Build 8ca218e2-352d-4c44-9118-20921fe4ab8e
💛 - Coveralls |
Are we sure that it is better to speed up the bootstrap time by 35ms while slowing down the first request response? |
Yes @kamilmysliwiec, it's the same idea in this PR nestjs/swagger#2392. Basically benefits those who run serverless. |
And what about the majority of users that don't run apps on serverless? Lazily initializing a document is a slightly different optimization - it wouldn't affect application's end-users but just developers (which is fine) |
Co-authored-by: Vinícius Lourenço <vinicius.cardoso7252@gmail.com>
Regardless of where you deploy a NestJS application, it's ideal to have it initialize as swiftly as possible to ensure prompt request handling. Although a slower initial request doesn't heavily impact NestJS performance, a slightly delayed startup can be somewhat inconvenient. Furthermore, not all routes necessitate the use of ValidationPipe. It's possible that the API's first incoming request is for a public route, causing the entire API to incur a penalty for that solitary route. |
I'd rather say it's ideal to have a fully functioning application - not a partial one that requires loading basic features (like validation) on demand. We don't really defer loading anything, that's the philosophy & a reason why features like async providers were introduced in the first place. |
@kamilmysliwiec Don't it worth at least having an option for the user, something like |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently the default behavior of the ValidatorPipe is to load the ClassValidator and the ClassTransformer as soon as the application starts, this took 35ms on my machine:
What is the new behavior?
Now the behavior has been modified so that it loads when receiving the first request.
Does this PR introduce a breaking change?