On Wed, Jan 13, 2021 at 2:32 AM Tekman <tekma...@gmail.com> wrote:
>
> Hi,
>
> What is the most efficient way to compile a (large) script that is being 
> passed in as an UTF-8 char buffer?
>
> The ExternalOwningOneByteStringResource is really nice for ASCII buffers, but 
> it looks like for UTF-8 we need to copy the entire contents and covert with 
> NewFromUtf8. It also looks like this memory (converted script source) sticks 
> around for the lifetime of the Isolate.
>
> For really large bundles, it's a waste to keep 2 copies of the script source 
> in memory; are there any optimizations / alternatives to consider?
>
> How feasible would it be to create something like 
> ExternalOwningUTF8StringResource?
>
> Thank you!

There is no way around the conversion. One way or another, you're
going to have two copies, because V8 doesn't use UTF-8 internally. JS
strings are either one-byte or two-byte. V8 does the UTF-8 conversion
at the edges.

The way I solved it in Node.js is by storing the built-in scripts as a
ExternalOneByteStringResource when they're Latin-1, and
ExternalStringResource (two-byte) otherwise.

It's not great for big scripts because approximately half of that
two-byte memory is zero, but on the flip side, it's in read-only
memory and doesn't count towards the JS heap limit.

If you're bundling scripts into your executable and you're worried
about executable size, one approach is to store the sources compressed
and decompress-and-stream them using ScriptCompiler::StartStreaming().
The uncompressed script source stays around for the lifetime of the
script, however.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAHQurc8_Voz06%2BLjFaKacZ%3Ds47WUEbLjTLcxrfxCj9eiytwayA%40mail.gmail.com.

Reply via email to