Skip to content

Commit

Permalink
optimize copying data chunks into a single array (#696)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Performance Improvements**
- Enhanced media chunk processing for better efficiency and reduced
memory usage when combining media data into a single array.

- **Bug Fixes**
- Resolved potential performance issues related to the handling of
multiple intermediate arrays.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
tak-hntlabs authored Aug 9, 2024
1 parent 0924184 commit 4a4e4e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1484,9 +1484,14 @@ export class Client
if (!mediaInfo) {
return undefined
}
const data = mediaInfo.chunks.reduce((acc, chunk) => {
return new Uint8Array([...acc, ...chunk])
}, new Uint8Array())
const data = new Uint8Array(
mediaInfo.chunks.reduce((totalLength, chunk) => totalLength + chunk.length, 0),
)
let offset = 0
mediaInfo.chunks.forEach((chunk) => {
data.set(chunk, offset)
offset += chunk.length
})

return decryptAESGCM(data, secretKey, iv)
}
Expand Down

0 comments on commit 4a4e4e1

Please sign in to comment.