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.
Inspired by https://twitter.com/4Kschool/status/1737218913212170699, I tried to search for performance improvements in this library.
perf(circuit): use bitset instead of storing valeus inside circuit
Basically, with this change, I tried to condense and reduce the amount of fields/memory needed to store the same information.
perf(circuit): remove amount of listeners
Instead of incrementing the metrics using listeners, I directly increase the number together when I emit the event.
This can introduce a little bit of maintenance burden but also save some memory and increase a little bit the performance for
.emit
since they didn't need to call a function.perf(semaphore): reduce memory footprint for semaphore
With this rewrite, I reduce the amount of memory needed and this also improves the instantation time of this class.
refactor(semaphore): removed unused timeout
Was not used by this library, so I removed it, let me know if you plan something with this feature and I can revert this commit.
perf(circuit): avoid cloning args
Now we have a specialized function that receives the array and we don't need anymore to shallow-clone the args twice.
perf(circuit): avoid calling errorFilter when not needed
Just a minor perf improvement, avoid calling a function that we know the result.
perf(circuit): avoid args cloning on fallback fn
This is a little bit more controversial, I didn't see any reason to avoid modifying the
args
array, so this can save a little bit of memory by avoiding this shallow-clone.perf(status): avoid creating array unecessary for bucket keys
Trying to reduce the amount of memory allocated by caching the keys instead of capturing those keys every time.
perf(status): prefer modify original array instead concat old arrays
There's no reason to avoid modifying that array since it was created during
.reduce
, so this helps the performance a little bit and also saves a little bit of memory.perf(semaphore): avoid promise creation when is not needed
A simple change that speeds a little bit the
fire
action since we avoid creating an unnecessary promise.In general, I tried to measure the perf improvements and using bench-node I got the following results:
Before:
After:
benchmark code
I also tried to measure the overhead of simple fire using the following code:
The output using
hyperfine
is:Before:
After: