Skip to content

Add noAssert to Buffer::write #4126

@kyriosli

Description

@kyriosli

Currently the new Buffer(string) constructor calls utf8Length and write, which can be very slow, because Buffer::write calls StringBytes::Write and which calls v8::String::WriteUtf8 with a buffer address and its capacity same as the utf8Length of the string. But v8::String::WriteUtf8 will be very fast if passed with a capacity equals to or larger than three times of the string length (see here).

So I think, why don't we manually make sure the capacity of the buffer is large enough, and pass a larger capacity (for example, three times of the string length) to the WriteUtf8 method, to make it faster?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions