Comments (4)
Okay, that's given me some insight on how to go about this the best way possible. I appreciate the assistance, Paul!
from jurassic.
I may be misinterpreting what you mean by a "session"; this is not a JavaScript concept as far as I know. Are you referring to the global state? In that case a ScriptEngine is a session, as essentially the whole purpose of the ScriptEngine class is to keep track of the JS global state. What it doesn't do is track what has changed in the global state, so the only way to reset it to a known state is to create a new ScriptEngine instance and then initialize it. (If you are doing this a lot then you may be able to speed it up a bit by using compiled scripts.)
from jurassic.
Yeah so basically what I was referring to is more or less standalone 'scope definitions' to avoid re-initializing the ScriptEngine
. I may be overthinking this, but would it not be a fair bit more expensive to re-instantiate & initialize the instance rather frequently? In my case I process requirements
for a command system
using the engine, which means that this operation could be called upon more or less anytime, however many times, depending on the user(s) executing commands.
from jurassic.
but would it not be a fair bit more expensive to re-instantiate & initialize the instance rather frequently?
It is expensive, yeah, on my computer it takes about 60ms just to initialize the a new ScriptEngine
instance, and that's not including any extra initialization you might need to do. Unfortunately if you require a freshly initialized ScriptEngine
there's no mechanism in Jurassic that'll speed this up. That doesn't mean there aren't things you can do, however:
- Initialize the new
ScriptEngine
instance(s) on a background thread(s). IndividualScriptEngine
instances are not thread-safe, but you can move them from one thread to another (you just can't do concurrent execution on a single instance). - Reset existing
ScriptEngine
instance(s) manually -- this can work if the changes to global state are limited, or if you know that only a subset of global state is important. - Prevent modifications to global state by using
Object.freeze()/Object.defineProperty()
or the C# equivalents. No need to reset the global state if the global state is immutable! - Do nothing fancy, just new up a new
ScriptEngine
instance each time you need one, it's fast enough. - Use a faster JS engine.
from jurassic.
Related Issues (20)
- Return value of CompiledScript HOT 5
- 3.2.1 backward compatibility issues HOT 4
- PropertyAccessorValue not visible HOT 1
- How to catch CLR Exception? HOT 7
- System.ArgumentNullException: Value cannot be null. (Parameter 'value') after update from 3.1.0 to 3.2.2 HOT 3
- JSONObject.Parse() fails when number is in scientific notation HOT 4
- ScriptEngine.EnableDebugging HOT 3
- Template of literals is slow
- JSON.stringify([].length) errors HOT 2
- JSONObject.Parse consumes more and more memory. Possible memory leak? HOT 11
- Scoping and CompiledScript.Execute vs ScriptEngine.Evaluate HOT 5
- Catching script errors at compile time HOT 2
- Currently JSONObject.Stringify returns object instead of string after upgrading from 3.1.0 to 3.2.6 HOT 3
- ScriptEngine.GetGlobalValue HOT 1
- Bug in Evaluate: Loop and variable handling HOT 2
- PM - Customer side scripting for Channels HOT 1
- Date.UTC() doesn't interpret two-digit years correctly HOT 1
- Linux compability ? HOT 4
- Is it possible to go from JS to DLL and then to C# source? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jurassic.