Task evaluation without tree
A task is currently defined as:
:: Task a = Task (Event -> TaskEvalOpts -> TaskTree -> *IWorld -> *(TaskResult a, *IWorld))
As far as I can see (correct me if I'm wrong), this task function remains the same while it is executed and the state is encoded in the
TaskTree. This has two disadvantages:
- It is bad for code quality, as task implementations have to deal with matching the tree with the task at runtime. This can for instance go wrong and result in errors at runtime.
- It is not efficient. Even after eliminating all JSON de-/encoding, for my coast guard application currently dynamics take 18% of the runtime.
I propose to let a task rewrite itself, such that we get:
:: Task a = Task (Event -> TaskEvalOpts -> *IWorld -> *(TaskResult a, Task a, *IWorld))
So the state is kept implicitly in the task function. I think with this design, no JSON/Dynamics would be required to internally pass task results, only at the instance level.
I see that a task tree is handy for inspecting the structure of the task, for instance for debugging. There is however nothing wrong with letting tasks (optionally) produce a task tree for this purpose.
Or is there another good reason for using a task tree I don't see? @baslijns? Otherwise, I'd explore this idea further and try to adapt the implementation.