Skip to content

Fix local heap allocations inside the OpenFOAM Reader

The GetCell method from the vtkFoamLabelVectorVector class is resizing a CellType = std::vector<vtkTypeInt64> which cause many temporary heap allocations (~800000 for the motor bike foam data set).

The fix replaces the std::vector with a custom StackVector which behaves exactly as a vector except that the memory is on the stack if and only if the required size is under a certain value.

Tests on the motor bike foam data shows a 3.8% speed improvement (from 425.4ms ± 6.2ms down to 409ms ± 3.3ms) and a 9.6% speed improvement on the 5gb 10M_example (11.2s ± 0.124s down to 10.124s ± 0.06s). Tests have been run 100 times with warmup on a Dell XPS machine.

Merge request reports