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.
This Pull Request addresses #81
Foreword
I believe that this Pull Request contains the right ideas to make
cron-validate
perform reasonably fast. However, I am not sure if my implementation aligns with your designs idea @AirfoooxThus, please let me know if you disagree with the implementation and we can try to find a better means to integrate the performance improvements into the library.
Description
This Pull Request introduces two small optimizations that makes
cron-validate
x100 faster when called in a loop. The changes are:options
") instead of when callingvalidateOptions
. Since the build-in presents do not change, we can load them just once instead of loading them every time that we usecron()
cron()
with the same settings multiple time (defined by preset/presetId and overrides), then we would spend quite a lot of time creating and validating anOptions
object. The creation & validation of this object makes the library about x100 faster when called in a loop.Benchmarking
I used this script for benchmarking, using some cron expressions akin to the ones I have been dealing with in production:
To execute the benchmark, first you need to delete the line
"type":"module"
frompackage.json
. The output produced by the compiler is CJS, so we cannot import it successfully if we mark the package as ESM. Then, execute the following:git checkout $branch npm run build node profile.mjs
On my machine, these are the results for
next
:These are the results for
make-cron-validate-x100-faster
: