I think the string source needs to be Unicode (or Latin-1) to easily 
convert from character offsets to byte offsets. Obviously, that's not 
possible with UTF-8. If you're really concerned about the memory, you could 
get rid of the original UTF-8 string once it's been converted to Unicode or 
convert the UTF-8 to Unicode yourself (in an external string) and then get 
rid of the UTF-8. But even saving both UTF-8 and Unicode copies of the 
script, I suspect the compilation data (byte-code, optimized code, objects, 
constants, property names, function templates, etc.) will end up taking 
more memory than your two copies of the source. Plus, memory's ubiquitous 
and cheap these days. So don't worry, be happy.

That said, if you're really keen on saving memory you could always use a 
minimizer but IMO that's valuing memory more than people.   

HTH
On Tuesday, January 12, 2021 at 8:32:40 PM UTC-5 Tekman 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!
>

-- 
-- 
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/5635fb59-52cf-47b1-93eb-83a063051603n%40googlegroups.com.

Reply via email to