Updated b64toByteArrays function to improve performance #97
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.
Hello,
I'd like to contribute some code improvement related to performance.
The function
b64toByteArrays
is critical for performance of the component as it makes heavy computation iterating on byteCharacters and so on.I wanted to improve this function as applied to many image it has a huge impact. I made some tests with a slightly different code that give great results:
Original code:
Propose code:
Here are the results of some naive benchmark, but hopefully, the improvement is significant even without advanced benchmark setup:
The benchmark was made on
Node.js v22.1.0
on MacOS.Here is the code used for the benchmark for the original code: (The same can be done for the new code)
I removed
contentType
parameter as well as it seems it is not used.Disclaimer: I have not made extensive checks across browsers to check performance and correctness except on Chrome, but basically there is no new API usage, just a slight change of the code for the sake of the performance.
I see the codebase of the library is not updated for quite some time now, hopefully this change may be applied anyway as the library is still widely used :)