perf(common): faster random string generator #10825
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
The method
randomStringGenerator
is implemented withuuid
package, which is slow when we compare with other package likeuid
:This method is also used inside
instance-wrapper.ts
, which is instantiated a lot during the initialization of NestJS, above the profiling information:The last call
unsafeStringify
is the problem.Issue Number: N/A
What is the new behavior?
I added a new package called
uid
based on the previous benchmark to generate faster random strings.Now, when we see the profiling information:
We have almost 3k ticks less than the previous version using
uuid
, when we search foruid
, we found this line:Much faster compared to 174 ticks from the previous package.
From my tests, creating 10,000 times an API with 20 modules, I went from 7.1213ms to 6.451ms to initialize NestJS.
This value can fluctuate depending on the machine and how many times you run but my baseline of improvement was the profiler information.
Does this PR introduce a breaking change?
Other information