Skip to content

Conversation

@praasz
Copy link
Contributor

@praasz praasz commented Nov 25, 2025

Details:

  • Changes fix performance for standard subscribe operator for Shape and PartialShape types.
  • reference operator[](std::ptrdiff pos) -> reference operator[](typename std::vector::size_type pos)
    The subscribe will same implementation as std::Vector for fast access elements.
  • reference operator()(std::ptrdiff pos) -> access element with normalization to shape size without bound check.
  • reference at(std::ptrdiff_t pos) -> access element with normalization to shape size with bound check.
  • update unit tests

Tickets:

@github-actions github-actions bot added category: Core OpenVINO Core (aka ngraph) category: GPU OpenVINO GPU plugin category: Python API OpenVINO Python bindings category: transformations OpenVINO Runtime library - Transformations category: CPP API OpenVINO CPP API bindings labels Nov 25, 2025
@praasz praasz changed the title [core] Change ov::Shape and ov::PartiaShape APU for subscribe operator [core] Change ov::Shape and ov::PartiaShape API for subscribe operator Nov 25, 2025
@mvafin
Copy link
Contributor

mvafin commented Nov 25, 2025

@praasz Could you provide example of incorrect operator usage that causes performance degradation?

@praasz
Copy link
Contributor Author

praasz commented Nov 25, 2025

@praasz Could you provide example of incorrect operator usage that causes performance degradation?

Here is sample of fix: #30388
If operator[] is used e.g. in loops is not optimized and creates overhead.

There could be some other places but they where not obviously noticed

The same issue pop-up during using ov::Shape for VectorDims alias (unify this type to shape can also remove some unnecessary conversions but operator[] creates degradations).

Using operator[] with negative position is not intuitive on C++ and it should be as fast as possible (unfortunately current implementation is not good and is hard to deprecate)

This is reason to introduce some additional operator like () which user must explicitly use and will do something similar like []
But operator can be replaced by some function call instead.

For functions at the behavior is same as current as this do bound checks and is slower byte default, but can be replaced by other functions too if required.

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

Labels

category: Core OpenVINO Core (aka ngraph) category: CPP API OpenVINO CPP API bindings category: GPU OpenVINO GPU plugin category: Python API OpenVINO Python bindings category: transformations OpenVINO Runtime library - Transformations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants