Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Copies data between node Buffers and/or ArrayBuffers up to ~75 times faster than in pure JS.
Copies data between node Buffers and/or ArrayBuffers up to ~75 times faster than in pure JS.
node.js utilizes a non-standard concept of I/O buffers and thus has both its Buffer as well as ArrayBuffer support. While Buffers are nice because they are a lot faster than V8's ArrayBuffers, transferring data between those two types can be ridiculously slow. This is where a node module like memcpy comes into play.
i memcpy.100k > cc Buffer -> Buffer: 22.222ms
i memcpy.100k > cc Buffer -> ArrayBuffer: 23.548ms
i memcpy.100k > cc ArrayBuffer -> Buffer: 22.108ms
i memcpy.100k > cc ArrayBuffer -> ArrayBuffer: 21.778ms
i memcpy.100k > js Buffer -> Buffer: 23.163ms
i memcpy.100k > js Buffer -> ArrayBuffer: 1043.713ms
i memcpy.100k > js ArrayBuffer -> Buffer: 1003.351ms
i memcpy.100k > js ArrayBuffer -> ArrayBuffer: 1607.978ms
Buffer
to Buffer
is about as fast as using Buffer#copy
Buffer
to ArrayBuffer
is about 45 times fasterArrayBuffer
to Buffer
is about 45 times fasterArrayBuffer
to ArrayBuffer
is about 75 times fasterArgument | Type | Optional | Description |
---|---|---|---|
target | Buffer|ArrayBuffer | Target buffer to copy to | |
targetStart | number | omittable | Target offset to begin copying to |
source | Buffer|ArrayBuffer | Source buffer to copy from | |
sourceStart | number | optional | Source offset to begin copying from |
sourceEnd | number | optional | Source offset to end copying from |
@returns | number | Number of bytes copied |
npm install memcpy
var memcpy = require("memcpy"), // C++ binding if available, else native JS
memcpy_binding = memcpy.binding, // C++ binding or NULL if not available
memcpy_native = memcpy.native; // Native JS
...
Please keep in mind that - besides the nice numbers - this is still to be considered experimental. I'd love if you'd review the C++ code to validate that it's safe. I can't yet think about a sane use case, though, as just sticking with Buffers on node.js and ArrayBuffers in the browser should be best practice.
License: Apache License, Version 2.0
FAQs
Copies data between node Buffers and/or ArrayBuffers up to ~75 times faster than in pure JS.
The npm package memcpy receives a total of 13 weekly downloads. As such, memcpy popularity was classified as not popular.
We found that memcpy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.