diff --git a/src/tree_node.cpp b/src/tree_node.cpp
index 0351f76e7..7b7a4ac88 100644
--- a/src/tree_node.cpp
+++ b/src/tree_node.cpp
@@ -106,13 +106,19 @@ NodeStatus TreeNode::executeTick()
     if(!substituted)
     {
       using namespace std::chrono;
+
       auto t1 = steady_clock::now();
+      // trick to prevent the compile from reordering the order of execution. See #861
+      // This makes sure that the code is executed at the end of this scope
+      std::shared_ptr<void> execute_later(nullptr, [&](...) {
+        auto t2 = steady_clock::now();
+        if(monitor_tick)
+        {
+          monitor_tick(*this, new_status, duration_cast<microseconds>(t2 - t1));
+        }
+      });
+
       new_status = tick();
-      auto t2 = steady_clock::now();
-      if(monitor_tick)
-      {
-        monitor_tick(*this, new_status, duration_cast<microseconds>(t2 - t1));
-      }
     }
   }