| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…g arguments Marshalling a JS string to char* copied it with strdup on every call and parked each copy on a throwaway external string for GC to reclaim; the IsExternalOneByte fast path above it could never fire for runtime-created strings because the argument itself was never externalized. WriteValue now externalizes the argument in place via MakeExternal when the string is pure ASCII (UTF-8 byte count == UTF-16 length, the exact condition under which the buffer equals the string's one-byte content) and V8 permits it, so later marshals of the same string reuse the buffer with no copy. Non-ASCII, young-generation, and otherwise non-externalizable strings keep the previous copy-per-call behavior. The fast path is also now gated on an ownership registry in OneByteStringResource: only buffers this runtime created are known to be NUL-terminated UTF-8, while a foreign resource's data is Latin-1 with no terminator guarantee and can no longer be handed to native code blindly.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. ❤️ ShareComment @coderabbitai help to get the list of available commands. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
What
Marshalling a JS string to a native char* argument previously copied it with strdup on every call, parking each copy on a throwaway external string for GC to reclaim. The IsExternalOneByte fast path above that code could never fire for runtime-created strings, because the argument string itself was never externalized — the reuse design was half-wired.
This PR completes it:
Hardening
The pre-existing fast path blindly trusted resource->data() of any external one-byte string as NUL-terminated UTF-8 — but V8's resource contract promises Latin-1 content with no terminator. OneByteStringResource now keeps a thread-safe ownership registry, and the fast path only reuses buffers this runtime created (OneByteStringResource::Owns).
Safety notes
Tests
Two new specs in ReferenceTests.js, built on functionWithCharPtr echoing its argument pointer:
Full suite: 1378 tests, 0 failures (Debug, iOS simulator).
Open question for review
Whether the perf win justifies the added state (the resource registry) without a motivating benchmark — this PR exists to make that discussion concrete. If a real workload shows C-string marshalling is never hot, closing unmerged is a fine outcome.