nest
nest copied to clipboard
refactor(microservices): improve speed of grpc server initialization
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [x] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior?
Issue Number: N/A
In order to find grpc service descriptors, collectDeepServices
function recursively searches whole grpcDefinitions generated by protoLoader, which currently includes all descriptors like namespace, service, and field.
What is the new behavior?
Because field descriptors cannot have namespace as their child, they don't need to be recursively searched. They can distinguished by checking existence of 'format' field and they can be skipped from the search to speed up the process.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
In the project I am working on, proto models are heavily used.
It took more than 3 seconds in M2 MacBook Pro to run collectDeepServices
before the modification.
Now it takes around 300ms in the same environment after the modification
Pull Request Test Coverage Report for Build 9a0d37e7-42c8-4e54-a3ae-9b3a5c95c083
Details
- 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.002%) to 92.125%
Totals | |
---|---|
Change from base Build eacd3e56-4bed-4f5e-9bab-412a10335aab: | 0.002% |
Covered Lines: | 6738 |
Relevant Lines: | 7314 |