[Open Source] Svelto.Tasks - c# promises compliant multi-threaded task runner

Svelto.Tasks

Run Asynchronous promise compliant tasks in Serial, Parallel and from other threads exploiting full continuation.

FAQ:
What is Svelto.Tasks?

Svelto.Tasks is part of the Svelto Framework. It allows to run yielding IEnumerators in Serial, Parallel and between threads. It’s much more than it sounds, as the unique continuation feature allows to switch seamlessly between schedulers so that tasks can run at different times following the same simple flow. The ITaskRoutine interface allows to use Promises compliant tasks too.

Who’s using Svelto?

Svelto is the official framework of Freejam, so it’s extensively used to run Robocraft, Robocraft Infinity and Cardlife (plus new upcoming titles). I know other companies are using it, but unluckily I am not getting much feedback. Please let me know if you use it, as I’d like to be in contact.

Do you offer support for Svelto?

Svelto is open source and offered as it is. Unluckily I don’t have much time to invest on it beside what I need for our projects, but I will be glad to answer your questions as they come. Of course, being open source and hosted on github, feel free to send me pull requests.

OK, but what can I do with it?

It’s not simple to explain in few words the potentiality of the framework as it can easily be confused with many similar libraries out there. Svelto.Tasks contains many unique features. I tried to show them through my articles and the set of examples and unit tests that ship with the library. However I understand that, without a proper documentation, is hard to wrap one’s head around it at glance. I strongly suggest to experiment with it starting from what I offer, then I will be here to try to help whenever I can.

What can I do that I can’t do with Unity already?

Better question. I will list the unique features, from the most obvious to the less ones:

  • Allows to run yielding IEnumerator (you should see them as asynchronous tasks) on classes that are not Monobehaviour. For example: MyEnumerator.Run(), will run the enumerator on the UpdateMonoRunner scheduler through an always available static extension method. Fire and forget it.

  • There are several Schedulers available: UpdateMonoRunner, LateMonoRunner, CoroutineMonoRunner, StaggeredMonoRunner, PhysicMonoRunner. You can explicitly choose the runner to run your IEnumerator on using the static extension RunOnSchedule. For example: MyEnumerator.RunOnSchedule(new LateMonoRunner()) or using the standard ones MyEnumerator.RunOnSchedule(StandardSchedulers.physicScheduler).

  • Because of the Marshalling that the normal StartCoroutine must perform, using Svelto.Tasks should be always faster in every occasion.

  • You can yield very complex flow of tasks exploiting continuation. You can yield a serial collection of tasks, from a parallel collection of task, from a normal IEnumerator.

  • You can yield everything from other threads using the MultiThreadRunner. It works exactly like the other runners. However you must use the ThreadSafeRunOnSchedule() method instead.

  • A task running from the standard UpdateMonoRunner can yield and wait for a task running on a MultiThreadRunner. Synchronization between threads become much easier to manage.

  • Through the interface ITaskRoutine, you can setup OnFail (exception happened) and OnStop (task stopped explicitly) callbacks. All the other promise-like features are available using the same logic that the .Net task library uses (more on the examples)

  • Well, as I said, much more can be done, but it must be tried to get it properly. Please check articles and example for more insights.

  • Designed to be fast, light and allocation free.

Further Resources:

My blog: http://www.sebaslab.com/

Main Article: Svelto TaskRunner - Run Serial and Parallel Asynchronous Tasks in Unity3D - Seba's Lab

Article on optimizations: Svelto.ECS+Tasks to write Data Oriented, Cache Friendly, Multi-Threaded code - Seba's Lab

Github: GitHub - sebas77/Svelto.Tasks: Svelto Tasks - C# promises compliant multi-threaded tasks runner (many examples of usage and unit tests included)

2 Likes

New article written:

Learning Svelto Tasks by example: The Million Points example

Transforming 1 million points on the CPU with Svelto.Tasks.

Feedback is welcomed.

Wow. I don´t exactly know what for it could be used…but what immidiantly comes in my mind: simulations, like fluid simulations. Would something like this benefit of using your framework ?

I don’t blame you for having difficulties to find an application for this. TBH the demo is misleading, this kind of applications must actually run on the GPU this is what the GPU is for.

Svelto.Tasks is about running about anything on other threads without worrying much about it as long as you understand how concurrent data access works. That’s why the best is to use it with Svelto.ECS. If you write an Engine (system) totally encapsulated, you can just run its loop on another thread without any effort.

For example you can run all the custom physic for the wings (like we do in robocraft) on another thread, just changing the runner of the task.

I made a simple CPU benchmark out of the 1MillionParticles demo…I may improve it in future, but it’s already fun to use. Can you score ~1M particles? :slight_smile:

i got 950.000 on my 960m nVidia, intel 4720HQ

Very close to the max!

999936

that’s the max! Let’s step up the game then:

https://t.co/8DglzCGM1D

this is my result!

What does it actually test?

What kind of beast have you got?!?! This is a CPU benchmark, although the GPU may affect the final result.

14 core 28 thread intel i9 overclocked to 4.1 ghz

I knew that! That machine can easily score 3M

do you want to know how far you can get? I can update it :slight_smile: However your water cooling system will boil

CPU was at 65%

let us give it a try

well I can make it get to 100% if you are up for a challenge :slight_smile:

I’ll do it tonight :wink:

here you go…4M particles!

in reality the particles rendered are 1M, I just transform them 4 times. I can’t increase the number of particles without affecting the performance due to the CPU->GPU data upload which is not part of what I want to benchmark.

P.s: prepare to throw ice on the motherboard

Ended up with 2247168

Lennart