Skip to content

Manifold::cleanup() is very slow #94

Description

@cakarsubasi

I wrote a short benchmark function to test out the changes in build_manifold as follows:

HMesh::Manifold create_huge_manifold()
{
    std::vector<size_t> faces;
    std::vector<CGLA::Vec3d> vertices;
    constexpr auto x_size = 1'000UL;
    constexpr auto y_size = 1'000UL;
    faces.reserve((x_size - 1) * (y_size -1) * 4);
    vertices.reserve(x_size * y_size);

    for (size_t i = 0; i < y_size; ++i) {
        for (size_t j = 0; j < x_size; ++j) {
            auto x = 10.0 * static_cast<double>(j) / static_cast<double>(x_size);
            auto y = 10.0 * static_cast<double>(i) / static_cast<double>(y_size);
            vertices.emplace_back(x, y, 0.0);
        }
    }
    for (size_t i = 0; i < y_size - 1; ++i) {
        for (size_t j = 0; j < x_size - 1; ++j) {
            auto top_left = i * y_size + j;
            auto top_right = top_left + 1;
            auto bottom_left = top_left + x_size;
            auto bottom_right = bottom_left + 1;
            faces.emplace_back(top_left);
            faces.emplace_back(top_right);
            faces.emplace_back(bottom_right);
            faces.emplace_back(bottom_left);
        }
    }

    HMesh::Manifold m;
    HMesh::build_manifold(m, vertices, faces, 4);

    return m;
}

The flamegraph for this is as follows:

Image

Over 90% of the runtime is spent on cleanup, mostly to sort the maps in the IDRemap struct. Switching the internals to unordered_map sped up the function by quite a bit, but I can still fill up my 20GB memory+swap space with only about 4 million vertices which triggers the OOM killer.

Now, obviously build_manifold most likely won't be called with such detailed meshes since every operation ends up taking ages, but if cleanup is meant to compact memory usage, it is currently not doing that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions