# Optimizing performance of events when clearing nodes

**URL:** <https://discourse.slicer.org/t/optimizing-performance-of-events-when-clearing-nodes/23588>\
**Category:** Development\
**Created:** [May 25, 2022, 4:06pm UTC](https://discourse.slicer.org/t/optimizing-performance-of-events-when-clearing-nodes/23588 "2022-05-25T16:06:59Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 25, 2022, 10:29pm UTC](https://discourse.slicer.org/t/optimizing-performance-of-events-when-clearing-nodes/23588/10 "2022-05-25T22:29:44Z")

</div>

The code above where the qMRMLSubjectHierarchyTreeView isn’t updated upon ending the BatchProcessingState produces the following errors.

```auto
[DEBUG][Qt] 25.05.2022 18:24:45 [] (unknown:0) - Python console user input: slicer.mrmlScene.EndState(slicer.mrmlScene.BatchProcessState)
[ERROR][VTK] 25.05.2022 18:24:45 [vtkMRMLSubjectHierarchyNode (0000028BAFF77F30)] (D:\D\P\S-0\Libs\MRML\Core\vtkMRMLSubjectHierarchyNode.cxx:2114) - GetItemDataNode: Failed to find subject hierarchy item by ID 8
[ERROR][VTK] 25.05.2022 18:24:45 [vtkMRMLSubjectHierarchyNode (0000028BAFF77F30)] (D:\D\P\S-0\Libs\MRML\Core\vtkMRMLSubjectHierarchyNode.cxx:2827) - GetItemParent: Failed to find subject hierarchy item by ID 8
[ERROR][VTK] 25.05.2022 18:24:45 [vtkMRMLSubjectHierarchyNode (0000028BAFF77F30)] (D:\D\P\S-0\Libs\MRML\Core\vtkMRMLSubjectHierarchyNode.cxx:2114) - GetItemDataNode: Failed to find subject hierarchy item by ID 9
[ERROR][VTK] 25.05.2022 18:24:45 [vtkMRMLSubjectHierarchyNode (0000028BAFF77F30)] (D:\D\P\S-0\Libs\MRML\Core\vtkMRMLSubjectHierarchyNode.cxx:2827) - GetItemParent: Failed to find subject hierarchy item by ID 9

```

Looks like I’m possibly running into known issues as written up in [https://github.com/Slicer/Slicer/issues/6006](https://github.com/Slicer/Slicer/issues/6006) and [https://github.com/Slicer/Slicer/issues/4650](https://github.com/Slicer/Slicer/issues/4650).

Using the workaround mentioned in [https://github.com/Slicer/Slicer/issues/6006](https://github.com/Slicer/Slicer/issues/6006), I can get the subject hierarchy in the Markups module to refresh.

> Force subject hierarchy tree rebuild by temporarily switching to scene import mode:
> 
> ```python
> slicer.mrmlScene.StartState(slicer.vtkMRMLScene.ImportState)
> slicer.mrmlScene.EndState(slicer.vtkMRMLScene.ImportState)
> 
> ```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/6/c67e244b21c8c0a47be0d32802f6cbe49e783b84.png)

---

_[View the full topic](https://discourse.slicer.org/t/optimizing-performance-of-events-when-clearing-nodes/23588)._
