improve performance of cast$expr #11388
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.
Dont know if this is improving the overall performance, but should I improved some parts.
omitUndefined is now about 5 - 10 % faster
isPath is now about 40 % faster.
Benchmarks and their result:
MONGOOSE_DEV=1 node omitUndefined.js
var1 valid x 1,925,657 ops/sec ±0.56% (93 runs sampled)
var1 valid2 x 19,595,175 ops/sec ±2.95% (90 runs sampled)
var2 valid x 2,026,454 ops/sec ±0.30% (95 runs sampled)
var2 valid2 x 21,847,207 ops/sec ±0.43% (90 runs sampled)
MONGOOSE_DEV=1 node isPath.js
var1 valid x 894,729,315 ops/sec ±2.38% (85 runs sampled)
var1 invalid x 901,086,157 ops/sec ±2.30% (84 runs sampled)
var2 valid x 1,373,966,160 ops/sec ±0.21% (95 runs sampled)
var2 invalid x 1,376,078,120 ops/sec ±0.13% (93 runs sampled)
var3 valid x 914,513,098 ops/sec ±2.31% (86 runs sampled)
var3 invalid x 902,081,446 ops/sec ±2.33% (85 runs sampled)
var4 valid x 906,717,792 ops/sec ±2.29% (84 runs sampled)
var4 invalid x 914,859,437 ops/sec ±2.32% (86 runs sampled)
var5 valid x 523,148,950 ops/sec ±6.62% (87 runs sampled)
var5 invalid x 136,384,194 ops/sec ±3.14% (84 runs sampled)
Variant 2 is the chosen one. We should not use startsWith when we only want to check if the first character is a specific one.