-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
performance isolates #51603
Comments
This is going to depend on a number of factors
|
The scenario is roughly the following. There is a set of unrelated tasks. For each task, a new isolate is created and uses the exit function to pass the result without copying. Would it be better to keep a ready pool of isolates in this case, or is the cost of creating an isolate always minimal (if the number of isolates is less than the maximum limit, more than 16 isolates cannot be created on my PC)? |
As @a-siva says, "that depends". Which operation dominates the computation? And is it speed or memory which is more important? If you use If you use an isolate pool, you spend no time creating an isolate, send the initial message, do the computation, then spend time copying back the result. And the isolate stays alive, taking up member, whether you use it again or not. The sending of the initial message and doing the computation are fixed costs. For small return values, not creating a new isolate is definitely faster. To find the cut-off point, you will have to measure your program. The start-up time of an isolate will most likely depend, at least a little, on the size of the program it's being spawned from. Even with fast isolate spawning and sharing of immutable data, there will be some setup to make space for global mutable variables, which exist per-isolate. The one further risk of an isolate pool is that you may get less parallelization. If you have 10 isolates in the pool, and you run 20 tasks, it will at most run 10 of those at a time. With 20 isolates, it can hypothetically run twice as fast. If the user has 20 CPU cores to run on, they're not doing anything else, and the stars are just right. But you can also use a growing isolate pool which creates new isolates so every concurrent request has its own isolate, then it reuses those isolates only when the computation is done. Then there is the memory cost of keeping isolates alive when they aren't needed any more. There will be some "pool maintenance" cost, but that's likely to be negligible compared to the actual computations. And there needs to be a pool strategy, which is at least:
All these decisions factor into how efficient the pool will be. (One example of a load-balancing pool is, from the no-longer-maintained |
From a code performance point of view, is it better to use isolate pools to send unrelated tasks to isolates for execution? Or is it possible to create a new isolate for each task without loss of code performance?
The text was updated successfully, but these errors were encountered: