# new vtkCutter in 9.4 has great performance loss

**URL:** <https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006>\
**Category:** Development\
**Created:** [December 12, 2024, 1:25am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006 "2024-12-12T01:25:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 12, 2024, 1:25am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/1 "2024-12-12T01:25:02Z")

</div>

I have used vtkCutter codes like the following:

```auto
vtkSmartPointer<vtkPlane> cutFunction = vtkSmartPointer<vtkPlane>::New();
cutFunction->SetOrigin(origin);
cutFunction->SetNormal(normal);

vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();
cutter->GenerateTriangleOff();
cutter->SetInputData(pointSetData); // pointSetData is vtkPointSet * (which is actually vtkUnstructuredGrid.)

cutter->SetCutFunction(cutFunction);
cutter->Update();

```

I have compared the performance of such codes between 8.2 and 9.4. It has great performance loss in version 9.4 ( **which I built 9.4 with tbb/mpi support, but without tbb build option setting in 8.2** ). I have debugged to trace the code inside vtkCutter (UnstructureGridCutter method) without any positive feedback.

Any idea on this behavior? Thanks.

---

<div class="post-metadata">

**Author:** ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)\
**Post date:** [December 12, 2024, 3:54pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/2 "2024-12-12T15:54:40Z")

</div>

Hi @cmodel. What kind of cells are in your unstructured grid. Can you provide an example dataset?

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [December 12, 2024, 8:00pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/3 "2024-12-12T20:00:01Z")

</div>

Yes, having a sample data set to reproduce the problem is essential. In addition to that, please provide more details:

- Have you built both VTK 8.2 and 9.4 in `Release` mode? (`Debug` mode can be 10x slower)
- What is the computation time in VTK 8.2 and 9.4?
- What operating system do you use?
- How exactly did you configure `tbb/mpi support`?
- How much total RAM do you have and what is the peak RAM usage during cutting?
- Where most of the time is spent? (you can determine it by building VTK in `RelWithDebInfo` mode and either use a profiler or just pause the computation during computation a couple of times and see what function/line you are at)

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 18, 2024, 1:42am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/4 "2024-12-18T01:42:04Z")

</div>

Hi @Andras, please see my answer.

> [@lassoan](#):
>
> Yes, having a sample data set to reproduce the problem is essential. In addition to that, please provide more details:
> 
> - Have you built both VTK 8.2 and 9.4 in `Release` mode? (`Debug` mode can be 10x slower)
> 
> ```auto
> Yes. both are in Release mode.
> 
> ```
> 
> - What is the computation time in VTK 8.2 and 9.4?
> 
> ```auto
> vtk8.2 - 2.845 sec
> vtk9.4 - 128.776 sec
> 
> ```
> 
> - What operating system do you use?
> 
> ```auto
> Windows 10 64bit professional
> 
> ```
> 
> - How exactly did you configure `tbb/mpi support`?
> 
> ```auto
> VTK_SMP_IMPLEMENTATION_TYPE TBB
> VTK_SMP_ENABLE_STDTHREAD checked
> VTK_SMP_ENABLE_SEQUENTIAL checked
> VTK_USE_MPI checked
> VTK_GROUP_ENABLE_MPI YES
> 
> ```
> 
> ![image](https://discourse.vtk.org/uploads/default/original/2X/0/021ca454af3363b353c6278987c520f2cc42ff90.png)
> 
> Advanced:  
> ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0efe806ea2cf70f110bf5a1f9b13eaf46b1e2ec3.png)
> 
> - How much total RAM do you have and what is the peak RAM usage during cutting?
> 
> ```auto
> 16G memory. peak memory usage has not been monitored.
> 
> ```
> 
> - Where most of the time is spent? (you can determine it by building VTK in `RelWithDebInfo` mode and either use a profiler or just pause the computation during computation a couple of times and see what function/line you are at)
> 
> ```auto
> have not built the version of RelWithDebInfo. We will try the debug version to see the most consumption position.
> 
> ```

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 18, 2024, 1:45am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/5 "2024-12-18T01:45:10Z")

</div>

Hi @cory.quammen , The test dataset has 384 thousand polyhedrons. I have exported the file into vtk xmlunstrucutred grid file, but it’s too large to transfer.

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [December 18, 2024, 4:17am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/6 "2024-12-18T04:17:50Z")

</div>

You can upload the file anywhere (dropbox, onedrive, google drive, github, etc.) and post the link here.

Please build VTK in RelWithDebInfo mode and report profiling results you get with that. Debug-mode builds are not usable for performance measurements, because the timings are completely different from release-mode builds.

Why have you enabled MPI?

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 18, 2024, 5:01am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/7 "2024-12-18T05:01:14Z")

</div>

You suggest I try one version without MPI enabled? @lassoan

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 18, 2024, 9:13am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/8 "2024-12-18T09:13:55Z")

</div>

Hi @lassoan @cory.quammen , I am afraid this test data set cannot be transferred to public domain. I will try some safe case to test this cutter issue.

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 18, 2024, 12:16pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/9 "2024-12-18T12:16:43Z")

</div>

@lassoan @cory.quammen

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/763fa06a002f01c002b864d110842d595a7ce735.png)

I debugged with the VTK version of ReleaseWithDebugInfo, it has 384k cells, and their types are polyhedron. For each GetDimension(), it will populate vtkPolyhedron. Here it takes much time.

I paused many times in some intervals, and here are some snapshots of the call stack.

vtkPoints  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/6/6b07e66bd0d1a2e77d70431d648b8ebd0a625e04.png)

vtkObjectFactory  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/362ae3028208205e3da789a97b8a1bb5f5b0b228.png)

vtkCellArray

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/95bd6c7614884b14d575b4c603e82eec5565bc71.png)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/353345472b7bd91ff439430a41964d3f4a64fda8.png)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9b43e8c6745afb45bfce74615a4f309ed13f1f09.png)

---

<div class="post-metadata">

**Author:** ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)\
**Post date:** [December 18, 2024, 12:31pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/10 "2024-12-18T12:31:07Z")

</div>

The issue [https://gitlab.kitware.com/vtk/vtk/-/issues/19499](https://gitlab.kitware.com/vtk/vtk/-/issues/19499) has already been fixed at commit [https://gitlab.kitware.com/vtk/vtk/-/commit/e2b77b6615600bb923a829b2d8a3c00818973a7d](https://gitlab.kitware.com/vtk/vtk/-/commit/e2b77b6615600bb923a829b2d8a3c00818973a7d) which can be double checked that is part of 9.4.0 here [https://gitlab.kitware.com/vtk/vtk/-/blob/v9.4.0/Common/DataModel/vtkCellTypes.cxx](https://gitlab.kitware.com/vtk/vtk/-/blob/v9.4.0/Common/DataModel/vtkCellTypes.cxx).

You can clearly see that the polyhedron case is handled properly.

If that’s not the case for you maybe you have a release candidate of VTK rather than the 9.4.0 release.

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 19, 2024, 9:45am UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/11 "2024-12-19T09:45:17Z")

</div>

@spyridon97 OK. I have changed to the release instead of RC2. The cutter has improvement compared to the RC2, but still slower than what it is with 8.2  
I built 9.4 (release) with TBB.

I tested the following data:

```auto
unit is second
case | mesh | vtk8.2 | vtk9.4
dataA | 380K polyhedron | 3.001 | 3.796
dataB | 230K polyheron | 0.664 | 0.785
dataC | 3.68 million tetra | 0.834 | 1.198
dataD | 6.21 million tetra + prism | 0.849 | 2.476
dataE | 19.65 million tetra + prism | 5.786 | 19.667

```

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 19, 2024, 12:05pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/12 "2024-12-19T12:05:26Z")

</div>

Hi @spyridon97@cory.quammen @lassoan

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0f8a67af244b0eaa4ef1037cb860c7faaac5805b.jpeg)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/2cb94d3cd2dcdc39d3e77cc49a011dbbf818b602.png)

I tested the above data set with the codes in the screenshot.  
Is there any wrong usage with the latest vtk9.4 ?

---

<div class="post-metadata">

**Author:** ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)\
**Post date:** [December 19, 2024, 5:08pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/13 "2024-12-19T17:08:53Z")

</div>

I can not tell what takes time without having a dataset.

If you have a dataset, let me know.

---

<div class="post-metadata">

**Author:** ![cmodel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/7ab992/32.png) [@cmodel](https://discourse.vtk.org/u/cmodel)\
**Post date:** [December 20, 2024, 5:23pm UTC](https://discourse.vtk.org/t/new-vtkcutter-in-9-4-has-great-performance-loss/15006/14 "2024-12-20T17:23:10Z")

</div>

Hi @spyridon97 @cory.quammen @lassoan  
I have uploaded one test dataset (810 MB)in the web storage site [filen.io](http://filen.io).  
But I cannot get the public share link since I have not the subscription of that site.  
Do you mind sign up, then I add you as the contact and share the link? Thanks.

> **[Filen – Next Generation End-To-End Encrypted Cloud Storage](https://filen.io/r/130f1038c822f25a5e8ae426d3550f69)**
>
> Filen – Next Generation End-To-End Encrypted Cloud Storage. Get started with 10 GB of free space.
