Performance when starting a new instance of a script engine #567
Replies: 1 comment 7 replies
-
Hi @DoctorGester,
Agreed.
The loader's job is simply to retrieve file content. The default loader caches each loaded file in memory, avoiding subsequent I/O for the same URL. We're unclear on what
So, the scripts in the "compat" directory are just normal (non-module) scripts that do nothing but install global functions and data? If you emit a trace after each one, do they all take roughly equal amounts of time to execute?
That's unlikely; the cost of import resolution should be dwarfed by the cost of loading the module. But to what imports are you referring? The only JavaScript module you're loading is "index.js". Does it load a bunch of other modules? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi,
We have a game server running multiple instances of a game with code in javascript. The current code takes about 2 seconds to start executing scripts on my M1 Pro. In an actual production container it takes even longer.
The code looks something like this:
and the resulting log looks something like this
So
new V8ScriptEngine
takes about 300ms give or take (there is other minor work happening to set up a custom import resolver), then adding host types is about 50ms, which is fine, but then actual script loading and initial execution takes 1500ms more. That last part is what is bothering me.sloc
reports36590
lines of code which is not "a lot" by V8 standards, I definitely don't expected it to compile code as slowly as at 25000 LoC/s. I have tried adding a compiled code cache in my custom loader, like this:However this has achieved no significant speedup, although I'm not sure I'm doing it correctly. Even when all scripts have a cache and are loaded from that cache (it takes sub 3ms per script to read and validate the cache), there are significant pauses between
LoadDocumentAsync
calls up to 40ms. We have no significant work in scripts which is happening at the top level, it's mostly function definitions and variables, no computation. Are there any load time optimization tricks I'm missing? Why would document loading be so slow? Is that because of a "ping-pong" between V8 and C# code when resolving imports?Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions