Using Compile with Execute and Script

Sep 10, 2015 at 8:50 PM
I have an application (with V8ClearScript) where the user occasionally loads a collection of script libraries. They then develop a Main script that can call those library scripts. The Main script will execute on a timer that may scan anywhere from once every 1 second to once every 10 seconds - most likely closer to 1 second.

It sounds like my best bet is to precompile the scripts. Generally the user may reload everything if they make changes to the library scripts. The user may just reload the main script if they make changes to just the main script. The user then can put the main script on scan or take it off scan before reloading.

Do first compile the script then execute the script?
ThisScript = Engine.Compile(scriptFile)
When the timer is on I use the Script method to call a specific function name in the main script. The user understands that if they want to run a script every scan it must be in the main script and a function named Main() must exist in that script.
Sep 11, 2015 at 1:15 PM
Hi johnsev,

Do first compile the script then execute the script?

Yes, that's correct. Note that compiling a script only makes sense if you need to execute it more than once in a given V8 runtime. If you re-execute a script only when it changes, compiling it provides no benefit.

Also, consider what the script actually does. If all it does is define a script function and invoke it, there's no need to re-execute it, as you can invoke an existing script function as many times as necessary. The main goal is to avoid redundant use of the script parser/compiler, as it's relatively slow.

Good luck!