-
Notifications
You must be signed in to change notification settings - Fork 150
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
? |
No description provided.
The text was updated successfully, but these errors were encountered: