Is an object pool suggested for speed performance? #999
Replies: 7 comments
-
There was some work done earlier to make engine instantiation faster, #625 . Engine will of course load features on demand so if you urilize all JS constructs the engine needs to initialize them lazily. Caching the parsed program helps too. Sharing engine has the problem of old global state. |
Beta Was this translation helpful? Give feedback.
-
@lahma what is your opinion about being able to mark an ObjectInstance immutable, such that we would not be able to change the builtin constructors, or mark pre-defined properties as not configurable. This way we could just re-initalize the lexical environments and reuse the engines. The main benefit would be that these built-in elements wouldn't have to be re-created. It doesn't seem very hard to do, at least for the most obvious properties and constructor objects. Also it should be easy to cover everything as it would mean anything that has a property name currently in the engine code. Forgive me if that's something I have already asked somewhere else ;) |
Beta Was this translation helpful? Give feedback.
-
I'm not against the idea, just a bit afraid of the complexity that might be involved with this freezing. I don't know if there's a cut-off point where we could declare engine fast to create and that wouldn't matter too much? My gut feeling is that engine creation is now quite fast, but initializing the state into engine is the problem. Say that you want to include couple MB of your support scripts - most of the time will be spent parsing and preparing. So might the actual requirement be to be able to inject start state faster into engine? Or if you mean these startup scripts as built-in elements then this would rhyme with what you expressed. This is also somewhat related to #665 , #491 and #673 Of course we can always try to make engine creation even faster 🙂 And I want to end with a JS rant when I was thinking about inlining some known functions for performance:
This is why we can't have nice things 😠 |
Beta Was this translation helpful? Give feedback.
-
I can see these two levels of reusability:
Maybe the second option is also the way to implement option 1. Though freezing a state (default engine state) is even faster for perf than having to clone a snapshot (allocations). |
Beta Was this translation helpful? Give feedback.
-
But yeah, option 1 means we would disallow things like |
Beta Was this translation helpful? Give feedback.
-
@rushfrisby I'm working on PR #789 , you might want to follow that development and please chime in if it's missing something. |
Beta Was this translation helpful? Give feedback.
-
Immutables is a nice solution to this. Keep a shared Math instance until you change it, then it becomes a new instance dedicated for that engine. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
With some other javascript engines I found that instantiating the engine was very expensive and to combat this I created an object pool of engines. Would you suggest this approach for Jint as well or is creating an engine lightweight enough that it isn't needed?
Beta Was this translation helpful? Give feedback.
All reactions