AcademySoftwareFoundation / openvdb

OpenVDB - Sparse volume data structure and tools
http://www.openvdb.org/
Mozilla Public License 2.0
2.5k stars 629 forks source link

meshToVolume slowdown? #1817

Open MakotoChiba opened 2 months ago

MakotoChiba commented 2 months ago

I'm using openvdb 6.2.1 on the windows11. meshToVolume getting slower and slower when system have lots of VDB grids. Larger grids and many of grids get more significant slower. And even if I delete the stored array, slowdown speed will not be restored. Why is this happens?

Here is the simple test code.

std::vector<openvdb::FloatGrid::Ptr> Grids
tempLS.resize(100, NULL);
DWORD start, end;

for (int j = 0; j < 100; j++)
{
    start = GetTickCount64();
    Grids[j] = openvdb::tools::meshToVolume<openvdb::FloatGrid>(polymesh, *transform, exBand, inBand, 0, &polyIndexGrid);

    end = GetTickCount64();
    printf("%d : %.3lf sec\n", j, (double)(end - start) * 0.001);
}

And This is part of the result. 0: 0.563 sec 1: 0.563 sec 2: 0.562 sec 3: 0.563 sec 4: 0.562 sec ~ 96: 0.758 sec 97: 0.753 sec 98: 0.764 sec 99: 0.753 sec 100: 0.762 sec This issue occurs when I have multiple openvdb::grid::Prt as well as std grid array.

If I don't store grids to array, it have no slowdown., like this

openvdb::FloatGrid::Ptr grid;
DWORD start, end;
for (int j = 0; j < 100; j++)
{
    start = GetTickCount64();
    grid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(polymesh, *transform, exBand, inBand, 0, &polyIndexGrid);

    end = GetTickCount64();
    printf("%d : %.3lf sec\n", j, (double)(end - start) * 0.001);
}

And This is part of the result. 0: 0.563 sec 1: 0.563 sec 2: 0.564 sec 3: 0.562 sec 4: 0.563 sec ~ 96: 0.568 sec 97: 0.563 sec 98: 0.574 sec 99: 0.563 sec 100: 0.572 sec

thanks

MakotoChiba commented 2 months ago

Here is another test code.

openvdb::FloatGrid::Ptr tempGrid;
std::vector<openvdb::FloatGrid::Ptr> tempLS;
tempLS.resize(400, NULL);
DWORD start, end;

for (int i = 0; i < 10; i++)
{
    start = GetTickCount64();
    tempGrid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(polymesh, *transform, exBand, inBand, 0, &polyIndexGrid);
    end = GetTickCount64();
    printf("%d : %.3lf sec\n", i, (double)(end - start) * 0.001);

    for (int j = 0; j < 400; j++)
    {
        tempLS[j] = tempGrid->deepCopy();
    }
}

This result is 0: 0.563 sec 1: 0.672 sec 2: 0.672 sec 3: 0.688 sec 4: 0.687 sec 5: 0.672 sec 6: 0.672 sec 7: 0.688 sec 8: 0.657 sec 9: 0.672 sec This means that have same problem which system have lot of array, meshToVolume get slower. But reuse of same grid array does not couse slowdown.

Then I add ->clear for array grid

openvdb::FloatGrid::Ptr tempGrid;
std::vector<openvdb::FloatGrid::Ptr> tempLS;
tempLS.resize(400, NULL);
DWORD start, end;

for (int i = 0; i < 10; i++)
{
    start = GetTickCount64();
    tempGrid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(polymesh, *transform, exBand, inBand, 0, &polyIndexGrid);
    end = GetTickCount64();
    printf("%d : %.3lf sec\n", i, (double)(end - start) * 0.001);

    for (int j = 0; j < 400; j++)
    {
        tempLS[j] = tempGrid->deepCopy();
    }
    for (int j = 0; j < 400; j++)
    {
        tempLS[j]->clear();
    }
}

This result is 0: 0.547 sec 1: 0.766 sec 2: 0.985 sec 3: 1.141 sec 4: 1.250 sec 5: 1.328 sec 6: 1.437 sec 7: 1.578 sec 8: 1.704 sec 9: 1.719 sec So, I get some more slow down. This means that grid->clear() might be cause heavy memory fragment or leak or something??

thanks