Skip to content

improve image rendering performance by less waited locking - #1164

Open
christianrauch wants to merge 1 commit into
ros-perception:rollingfrom
christianrauch:fix_image_view_locking
Open

improve image rendering performance by less waited locking#1164
christianrauch wants to merge 1 commit into
ros-perception:rollingfrom
christianrauch:fix_image_view_locking

Conversation

@christianrauch

Copy link
Copy Markdown
Contributor

The current implementation of image_view::ImageViewNode has bad performance. You roughly only see half of the images on screen that are published on the topic.

This PR improves the thread locking and shows the full framerate of images on the topic.

@ahcorde ahcorde left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not really sure about the solution here. I prefer the condition_variable approach.

Did you benchmark ?

Now, we can use cpp20 at least on lyrical and rolling. what's about std::binary_semaphore ?

Comment thread image_view/src/image_view_node.cpp
Comment thread image_view/src/image_view_node.cpp Outdated
@christianrauch

Copy link
Copy Markdown
Contributor Author

Did you benchmark ?

Not "professionally". When you see an image stream and compare it with rqt, it is obvious that the framerate is lower. Printing on the screen shows that the sync callback (imageCb) is called twice before an image is shown (cv::imshow).

@christianrauch
christianrauch force-pushed the fix_image_view_locking branch 2 times, most recently from 7ff4bd9 to eb180af Compare May 21, 2026 20:49
@christianrauch

Copy link
Copy Markdown
Contributor Author

Now, we can use cpp20 at least on lyrical and rolling. what's about std::binary_semaphore ?

What is the advantage of using the std::binary_semaphore over std::mutex in this case? From https://en.cppreference.com/cpp/thread/counting_semaphore it seems they would behave the same.

I replaced the mutex with the binary_semaphore now anyway. While technically, this seems to work the same, semantically using semaphore is easier to understand the purpose.

@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from eb180af to a283413 Compare May 21, 2026 21:01
@christianrauch

Copy link
Copy Markdown
Contributor Author

The CI is complaining about the new include #include <semaphore>:

    /__w/image_pipeline/image_pipeline/src/image_view/include/image_view/image_view_node.hpp:20:  Found C system header after C++ system header. Should be: image_view_node.h, c system, c++ system, other.  [build/include_order] [4]

There are no C headers in image_view_node.hpp, and there is no image_view_node.h in the repo.

@ahcorde Do you have any idea how to resolve this?

@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from a283413 to ac6f08d Compare May 24, 2026 22:50
@christianrauch
christianrauch changed the base branch from jazzy to rolling May 24, 2026 22:51
@christianrauch
christianrauch requested a review from ahcorde May 24, 2026 22:51
@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from ac6f08d to 27be393 Compare June 1, 2026 14:20
@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from 27be393 to 636e468 Compare June 22, 2026 20:54
@mergify

mergify Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@christianrauch

Copy link
Copy Markdown
Contributor Author

@ahcorde Can you take a look at this?

The CI report:

- image_view.cpplint build/include_order [4] (/__w/image_pipeline/image_pipeline/src/image_view/include/image_view/image_view_node.hpp:20)
  <<< failure message
    Found C system header after C++ system header. Should be: image_view_node.h, c system, c++ system, other.
  >>>

does not make sense to me. Line 20 includes a standard C++ header (#include <semaphore>) and there is no such header image_view_node.h.

@mikeferguson

Copy link
Copy Markdown
Member

The image_view_node.h part is a red herring I think, that's just the format of the error message (it lets you know that you can have a header file for the specific cpp file).

I think the issue is that cpplint is miscategorizing something as a "C system header" (I've seen that happen before - but I got no idea what is going on in this case).

Perhaps try reverting the change on line 25 and make cv_bridge still use quotes instead of brackets? (although I thought the rule was that a .h file would be considered a C system header if it was in brackets, not a .hpp file).

@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from 636e468 to 4776fb2 Compare July 6, 2026 19:52
@christianrauch

Copy link
Copy Markdown
Contributor Author

@ahcorde Please help me out here :-) I am not including any C headers. Can you please fix the linters to remove these false positives?

@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from 4776fb2 to 0a66831 Compare July 10, 2026 20:45
@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from 0a66831 to 03d9624 Compare August 2, 2026 15:07
@christianrauch

Copy link
Copy Markdown
Contributor Author

@ahcorde Can you take care of the linting in the CI? I reverted some of my header changes but still get the same warning. If the linting provides false positives, can you simply remove it?

@christianrauch
christianrauch force-pushed the fix_image_view_locking branch from bfec8fc to 89b9e36 Compare August 12, 2026 21:10
@christianrauch

Copy link
Copy Markdown
Contributor Author

@ahcorde I managed to avoid the problem by removing the <semaphore> header. I still don't understand why this could potentially be treated as a C header, but the package builds and the tests pass. Please check this again.

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.

3 participants