path: root/src/server/events/Disconnect.cpp
diff options
authorDavid Robillard <>2016-10-01 15:18:09 -0400
committerDavid Robillard <>2016-10-02 12:24:57 -0400
commita172e76897157e5a0d2ebd3fa3f7f77ec38a5df0 (patch)
treeafc1962fc5123ff8ad4558912e69227bca2a4192 /src/server/events/Disconnect.cpp
parent5c4356827e51b3d6e1256a050e6273a87728d588 (diff)
Defer graph compilation in atomic bundles
This avoids situations like compiling a graph hundreds of times when it is loaded because it has hundreds of nodes and each event triggers a re-compile. This speeds things up dramatically, but exacerbates the theoretical problem of there not being enough time in a cycle to execute a bundle. As far as I can tell, the execute phase of events is very fast, so hundreds or thousands can easily run in a tiny fraction of the process cycle, but this still needs resolution to be truly hard real-time. What probably needs to happen is that all context and state used to process is moved to CompiledGraph and nodes do not access their own fields at all, but have some references into the CompiledGraph. This way, a compiled graph is separate from its "source code", and an old one could continue to be run while a new one is beng applied across several cycles.
Diffstat (limited to 'src/server/events/Disconnect.cpp')
1 files changed, 8 insertions, 3 deletions
diff --git a/src/server/events/Disconnect.cpp b/src/server/events/Disconnect.cpp
index ed9312d5..476a0cee 100644
--- a/src/server/events/Disconnect.cpp
+++ b/src/server/events/Disconnect.cpp
@@ -29,6 +29,7 @@
#include "InputPort.hpp"
#include "OutputPort.hpp"
#include "PortImpl.hpp"
+#include "PreProcessContext.hpp"
#include "RunContext.hpp"
#include "ThreadManager.hpp"
#include "events/Disconnect.hpp"
@@ -55,6 +56,7 @@ Disconnect::Disconnect(Engine& engine,
delete _impl;
+ delete _compiled_graph;
Disconnect::Impl::Impl(Engine& e,
@@ -112,7 +114,7 @@ Disconnect::Impl::Impl(Engine& e,
+Disconnect::pre_process(PreProcessContext& ctx)
std::lock_guard<std::mutex> lock(>mutex());
@@ -166,8 +168,9 @@ Disconnect::pre_process()
- if (_graph->enabled())
+ if (ctx.must_compile(_graph)) {
_compiled_graph = CompiledGraph::compile(_graph);
+ }
return Event::pre_process_done(Status::SUCCESS);
@@ -204,7 +207,9 @@ Disconnect::execute(RunContext& context)
if (_status == Status::SUCCESS) {
if (_impl->execute(context, true)) {
- _graph->set_compiled_graph(_compiled_graph);
+ if (_compiled_graph) {
+ _compiled_graph = _graph->swap_compiled_graph(_compiled_graph);
+ }
} else {
_status = Status::NOT_FOUND;