-
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
Questions about module loading #169
Comments
Hi @JohnLudlow, First, we can't reproduce the poor performance you're seeing. In our testing, Second, we agree that the When it comes to performance, it makes sense that As for behavior, we believe that what you're seeing is all correct. When you use When you import the non-module To use the Lodash exports in both places, you can do something like this: engine.AddHostType(typeof(Console));
engine.Evaluate(new DocumentInfo { Category = ModuleCategory.Standard }, @"
import * as _ from 'e:\\node_modules\\lodash-es\\lodash.js';
Console.WriteLine(_.capitalize('tom'));
Function('return this;')()._ = _; // store imports in global property
");
engine.Evaluate("Console.WriteLine(_.capitalize('jerry'))"); ... or something like this: engine.AddHostType(typeof(Console));
engine.Evaluate(new DocumentInfo { Category = ModuleCategory.Standard }, @"
import 'e:\\node_modules\\lodash\\lodash.js'; // side effect import
Console.WriteLine(_.capitalize('tom'));
");
engine.Evaluate("Console.WriteLine(_.capitalize('jerry'))"); You can also export the Lodash imports from your module, if that's something that makes sense in your application. Good luck! |
Hi @ClearScriptLib, Thanks for your reply. I should have mentioned that the ~40s I noted was in debug. In release, it took about 1-3s to load lodash-es, which is reasonable an in line with your observation - were you running in debug or release? I can provide my test project if that would help, but I think the exceptions would have been a contributing factor and eliminating those would probably solve the debug performance issue I was seeing as well. I wasn't aware that side effect importing would work. That's probably the best option for most of what we want to do. Thanks also for the explanation for why importing the non-module lodash didn't do what I expect because that was slightly odd. |
Those numbers are consistent with our tests, for which we used a release build. Note that the performance gap here isn't just due to disk I/O but also over 300 invocations of V8's script parser, each of which has its own overhead and global optimization impact. We'll keep this issue open to track the |
…Hub Issue #160); fixed 64-bit V8 initialization on Azure App Service (GitHub Issue #166); enabled DirectAccess for ComVisible .NET objects (GitHub Issue #161); added ScriptEngine.ExposeHostObjectStaticMembers (GitHub Issue #152); added ScriptEngine.UndefinedImportValue and made Undefined.Value public (GitHub Issue #154); enhanced ExtendedHostFunctions.typeLibEnums to pull in external enumerations; added thread affinity enforcement in WindowsScriptEngine.Dispose; eliminated KeyNotFoundException when checking for system documents (GitHub Issue #169); enabled the use of the application's root folder as a backup for its local data folder (GitHub Issue #171); reduced minimum CPU profile and heap size sampling intervals to 125 ms; updated deployment and API documentation, resolving GitHub Issues #158 and #159. Tested with V8 8.1.307.28.
Version 6.0.1 eliminates the troublesome exceptions. |
Hi,
I've been experimenting with module loading, in particular loading lodash (no particular reason for that module - it's just a good test).
This works:
This takes about 40s to run, and I see a lot of
KeyNotFoundException
s fromDocumentSettings.FindSystemDocument
. Could there be a check there to see whether the document is already in the map?Now, we're interested in being able to import modules and allowing them to be used in non-module scripts and snippets:
This also works, and it's quick - this took less than a tenth of a second to run in my test and only threw one
KeyNotFoundException
. But an eagle-eyed observer might notice an oddity - in one example, I use the lodash-es module (the ECMAScript standard module) and in one their core module (from https://www.npmjs.com/package/lodash). I can't seem to make one variant work for both examples.Result:
_
is an empty object,capitalize
is not a function.Result: Works, a bit slow, throws KeyNotFound a lot.
Result: Works really nicely
Result: Is a bit slow, throws KeyNotFound a lot, then, throws a ScriptEngineException
ReferenceError: _ is not defined
on the second Evaluate.❓ What am I missing?
I've also been playing with system documents which give similar results.
The text was updated successfully, but these errors were encountered: