Skip to content

Conversation

Khizar1
Copy link

@Khizar1 Khizar1 commented Oct 12, 2025

…rs_*

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes open3d.utility.Vector3dVector() sometimes slow #5250
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

This PR fixes slow performance when constructing Open3D vectors (Vector3dVector) from non-contiguous NumPy arrays, such as Pandas DataFrames. Previously, pybind11 performed slow element-by-element deep copies due to the restrictive py::array::c_style flag in py_array_to_vectors_*. This change relaxes that restriction and performs a lightweight runtime check instead:

  • If the array is already contiguous -> no copy.
  • If not -> a single fast contiguous copy via NumPy.

Up to ~50× faster conversion for non-contiguous arrays. Please refer to benchmark results below.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

This PR improves array conversion performance in cpp/pybind/utility/eigen.cpp by replacing
the static py::array::c_style flag with a runtime check for contiguity.

Summary of Changes

  • Updated py_array_to_vectors_double , py_array_to_vectors_int, py_array_to_vectors_int_eigen_allocator and py_array_to_vectors_int64_eigen_allocator to:
    • Detect C-contiguous arrays at runtime (array.flags()).
    • Copy only if the array is not c-contagious.
  • No behavior change for contiguous inputs.

Benchmark Results

Vector Type Before (ms, Pandas -> NumPy) After (ms) Speedup
Vector2dVector 2602.73 126.28 ~21×
Vector2iVector 2502.89 49.43 ~51×
Vector3dVector 2640.17 164.48 ~16×
Vector3iVector 2607.42 69.98 ~37×
Vector4iVector 2567.23 85.04 ~30×

Reproducible script: benchmark_all_vectors.py

Tested on Ubuntu 24.04, Python 3.12 inside a Docker environment.

Copy link

update-docs bot commented Oct 12, 2025

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

open3d.utility.Vector3dVector() sometimes slow

1 participant