-
-
Notifications
You must be signed in to change notification settings - Fork 7
Buffer.byteLength and simdutf #66
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
Comments
To use simdutf to calculate the byte length of a string we need to access its content first, which usually requires copying its content to an address provided by us, I wonder if the copying already defeats any speedup brought by simdutf. If simdutf provides latin1 to utf8 transcoding/length calculation we might still be able to use that on known one-byte strings where the the speedup from SMID outweighs the copying overhead, but for strings that might not be one-byte (V8 only knows after traversing the string) the penalty of copying and even letting V8 to transcode a not-so-certain one-byte string into UTF16 first before copying the contents for us is probably too significant. |
I don't understand. The following code should be able to use simdutf without any additional copying. You already have direct access to the data through uint32_t FastByteLengthUtf8(Local<Value> receiver,
const v8::FastOneByteString& source) {
uint32_t result = 0;
uint32_t length = source.length;
const uint8_t* data = reinterpret_cast<const uint8_t*>(source.data);
for (uint32_t i = 0; i < length; ++i) {
result += (data[i] >> 7);
}
result += length;
return result;
} |
That's only hit in the case where the string is known to be one-byte and sequential (on the premise that fast API calls are hit). But even in this case, we can't use simdutf (yet), because simdutf does not yet have latin1-to-utf8 transcoding (it should have one soon, but for now, not yet) |
Probably duplicate #52 |
Buffer.byteLength
can be implemented more efficiently with simdutfThe text was updated successfully, but these errors were encountered: