[ENH] Make embeddingsToBase64Bytes 6-7x faster on node/bun #6129
+133
−4
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 PR adds an alternative implementation of
embeddingsToBase64Bytesfor environments with access toBuffer, for a 6-7x speed increase.I've been having trouble getting a lot of throughput when mass batch uploading documents using our JS client. I measured what was happening and one of the culprits was the
embeddingsToBase64Bytesfunction.I measured that when uploading batches of 300 docs w/ 1536 dim vectors, there was ~60ms of synchronous work being done before the API call. The largest culprit of which was
embeddingsToBase64Bytes.There's actually nothing wrong with the current implementation. Browsers do not have access to
Buffer, so the existing implementation is fine in light of that. I still want to have more performance on node and bun.I wrote a script to measure both implementations and this is what I get:
With this change, I should expect to get up to 50% more throughput on node and bun.