-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need best practices guides for performance and memory usage #101
Comments
I can't stress this enough. I'm trying to integrate this into my project, and I'd like to safely add usage and resource limits. What areas I'm struggling with:
If I wrap this in a using block, it will output:
and then dispose of the engine If I execute this, and add a |
Hi @danbopes,
We generally recommend that applications stay away from Originally this API was somewhat suitable for sandboxing, but the V8 team decided years ago that constrained script execution isn't a goal for V8. Today, exceeding any of the specified limits causes V8 to crash instantly, and that's by design. The API might still be useful for expanding V8's default limits, but we've found that V8 can then hit other limits that are inaccessible and vary unpredictably from version to version. ClearScript does offer support for "soft limits" (see The bottom line is that, unfortunately, if you must run untrusted script code with 100% safety, you'll need a Chromium-like multi-process architecture. The V8 team equates executing untrusted script code with invoking a function in an untrusted DLL. V8's API is constantly changing though, and we'll continue to watch for new developments.
For these purposes you can use
There's no special API for that, but you can always wait for a pre-arranged completion signal: engine.AddHostType("Console", typeof(Console));
engine.AddHostType("api", typeof(TestApi));
engine.Script.done = new ManualResetEventSlim();
engine.Execute(@"
Console.WriteLine('start');
const main = async () => {
Console.WriteLine('main');
var res = await api.delay('end');
Console.WriteLine(res);
done.Set();
}
main();
");
engine.Script.done.Wait(); Please send any additional questions or comments our way. Thanks! |
Hey everyone, I'm wondering how to "correctly" set the memory limits and this seemed like the best place to ask based on what I've found. But copying it here as well.... What properties I've found, so far: What properties I use + the values: Properties with default: Question:
The descriptions seem a bit vague to me, and I miss the default values in the documentation for them 😿 My current playground / flow:
What problem I'm trying to kinda diminish:
Could give me a hand, please, and help me understand a bit more (find more proper values)? With kind regards, P.s.: From what I've currently read here, we had wrong expectations / assumptions |
Hi Šimon,
The default value (zero) selects an internally enforced minimum, which is currently 50ms. Our recommendation is not to increase unless you encounter performance issues.
This probably won't be very helpful, but our understanding is as follows:
Ultimately, your ideal A potentially useful feature not mentioned above is on-demand heap expansion, which provides a way to increase the heap size limit when a script comes close to exceeding it. See Good luck! |
Hello, thanks a lot! What is the connection between What can be the max memory footprint of the engine if I have these values set: Is it recommended to explicitly call the GC on the V8 Engine before the instance gets dispose? About the HeapExpansionMultiplier And one more vs
then
? |
Hello Šimon,
They're unrelated. Memory for
No. Unlike failure to allocate memory on the JavaScript heap, V8 handles
Although ClearScript tracks that internally, there's no API for retrieving it. Sorry!
That's a difficult question to answer. Ignoring code, each V8 runtime includes managed data, native data (including Our understanding is that V8 crashes the process if any region of the JavaScript heap exceeds the corresponding V8 itself is unaware of There are other factors as well. For example, each V8 runtime reserves a significant chunk of address space up front, which can be a problem on smaller (32-bit) systems that use multiple runtimes in a single process. Last time we looked into it, V8 also had a number of internal limits that the host couldn't control or monitor, but we believe that recent versions have improved on that.
The default value of
If you're only using one engine, there's no difference. The Please don't hesitate to send additional questions and comments our way! Cheers! |
Well, this sounds really good. So, when the ArrayBuffer allocation rises up to the limit, the script fails. Thanks to u, I don't need any xtra polling or whatever to check/handle that. However, the max memory limit it can really reach (by my understanding) is "max heap limit + old heap limit + ArrayBuffer allocation limit".
Thanks for the cleaner explanation of how CS handles this.
Just being curious - what do values "0 -1" do?
Is About the occupied memory and the |
No description provided.
The text was updated successfully, but these errors were encountered: