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.

@update-docs
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.

@ssheorey ssheorey requested review from Copilot and ssheorey October 30, 2025 04:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a performance bottleneck when converting non-contiguous NumPy arrays (e.g., from Pandas DataFrames) to Open3D vector types. The fix removes restrictive compile-time flags and uses runtime contiguity checks instead, achieving up to 50× speedup for non-contiguous inputs while maintaining identical behavior for contiguous arrays.

Key Changes:

  • Modified four conversion functions to perform runtime contiguity checks instead of compile-time enforcement
  • Non-contiguous arrays now trigger a single fast NumPy copy instead of slow element-by-element deep copies
  • Updated CHANGELOG to document the performance improvement

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cpp/pybind/utility/eigen.cpp Replaced static py::array::c_style flags with runtime contiguity checks in 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
CHANGELOG.md Added entry documenting the performance fix for non-contiguous NumPy array conversion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,4 +1,5 @@
## Main
- Fix performance for non-contiguous NumPy array conversion in pybind vector converters. This change removes restrictive `py::array::c_style` flags and adds a runtime contiguity check, improving Pandas-to-Open3D conversion speed by up to ~50×. (issue #5250)(PR #7343).
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Add a space between '(issue #5250)' and '(PR #7343)' for consistency with formatting in other changelog entries.

Suggested change
- Fix performance for non-contiguous NumPy array conversion in pybind vector converters. This change removes restrictive `py::array::c_style` flags and adds a runtime contiguity check, improving Pandas-to-Open3D conversion speed by up to ~50×. (issue #5250)(PR #7343).
- Fix performance for non-contiguous NumPy array conversion in pybind vector converters. This change removes restrictive `py::array::c_style` flags and adds a runtime contiguity check, improving Pandas-to-Open3D conversion speed by up to ~50×. (issue #5250) (PR #7343).

Copilot uses AI. Check for mistakes.
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