node icon indicating copy to clipboard operation
node copied to clipboard

src: Fix inefficient usage of v8_inspector::StringView

Open szuend opened this issue 10 months ago • 13 comments

v8_inspector::StringView can either be one-byte or two-byte strings. Node has currently two places where it's unconditionally assumed that it's a two-byte StringView.

This requires the upstream V8 inspector to unnecessarily create a copy of the string:

https://source.chromium.org/chromium/chromium/src/+/main:v8/src/inspector/v8-inspector-session-impl.cc;l=192-199;drc=05bacd38e7a31e92afe0fd66081dfa2cc03b934a

This is particularly slow, especially for large CDP messages, as the serialized JSON is iterated 8-bit char by 8-bit char and each one widened to a 16-bit char.

This PR introduces a small helper that correctly converts a StringView to a v8::String instance honoring the "is8Bit" flag. This allows upstream V8 to remove the unnecessary widening copy.

Tested locally with removing the widening copy in v8-inspector-session-impl.cc: Without the PR lots of tests will fail. But I'm happy to add unit tests for the JSBindingsConnection/V8ProfilerConnection if desired.

szuend avatar Apr 05 '24 05:04 szuend

Failed to start CI
- Validating Jenkins credentials
✘  Jenkins credentials invalid
https://github.com/nodejs/node/actions/runs/8605010252

github-actions[bot] avatar Apr 08 '24 18:04 github-actions[bot]

@addaleax Anything I need to address from my side for the failed CI run?

szuend avatar Apr 09 '24 04:04 szuend

CI: https://ci.nodejs.org/job/node-test-pull-request/58242/

nodejs-github-bot avatar Apr 10 '24 18:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/58268/

nodejs-github-bot avatar Apr 11 '24 09:04 nodejs-github-bot

I'm not too familiar with the node CI. Are the failing tests from the two CI runs generally known to be flaky or should I investigate?

szuend avatar Apr 15 '24 05:04 szuend

CI: https://ci.nodejs.org/job/node-test-pull-request/58399/

nodejs-github-bot avatar Apr 15 '24 14:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/58428/

nodejs-github-bot avatar Apr 16 '24 12:04 nodejs-github-bot

Rebased the PR after https://github.com/nodejs/node/pull/51783 has landed.

FYI @joyeecheung

szuend avatar Apr 22 '24 07:04 szuend

CI: https://ci.nodejs.org/job/node-test-pull-request/58593/

nodejs-github-bot avatar Apr 22 '24 12:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/58639/

nodejs-github-bot avatar Apr 23 '24 14:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/58684/

nodejs-github-bot avatar Apr 25 '24 03:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/58751/

nodejs-github-bot avatar Apr 27 '24 15:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/58798/

nodejs-github-bot avatar Apr 29 '24 14:04 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/59446/

nodejs-github-bot avatar May 27 '24 11:05 nodejs-github-bot