Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use uint8.subarray instead of uint8.slice #2581

Open
ThaUnknown opened this issue Jun 13, 2023 · 1 comment
Open

perf: use uint8.subarray instead of uint8.slice #2581

ThaUnknown opened this issue Jun 13, 2023 · 1 comment

Comments

@ThaUnknown
Copy link
Member

when migrating to uint8 from node buffer, code which used .slice was not changed, node:buffer's slice creates a subarray, but uint8.slice creates a copy, this needs to be updated to use .subarray, this would be another very big performance gain

@ljluestc
Copy link

ljluestc commented Sep 3, 2023

// Original code with Node.js Buffer
const originalBuffer = Buffer.from(/* some data */);
const subBuffer = originalBuffer.slice(10, 20); // Creates a subarray

// Updated code using Uint8Array
const uint8Array = new Uint8Array(/* some data */);
const subArray = uint8Array.subarray(10, 20); // Creates a view without copying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants