Skip to content

Performance improvements in serialization#553

Merged
jmachowinski merged 2 commits intoros2:rollingfrom
cellumation:rolling
Feb 19, 2026
Merged

Performance improvements in serialization#553
jmachowinski merged 2 commits intoros2:rollingfrom
cellumation:rolling

Conversation

@jmachowinski
Copy link
Contributor

Description

Optimized functions that showed up in perf

Did you use Generative AI?

No

The dynamic_cast here turned out to be quite costly. Replacing
it by the variant like function, we see a ~10% cpu usage reduction
in our use case.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
This gives another performance improvement of around 2% of cpu
usage in our usage scenario.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
@jmachowinski
Copy link
Contributor Author

Pulls: #553
Gist: https://gist.githubusercontent.com/jmachowinski/ca2ea1f91f1b54f5a10a538c4436ad3f/raw/fe3c55c06f5168f50666341d58e579fc2802b6c2/ros2.repos
BUILD args:
TEST args:
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18220

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Contributor

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm with green CI.

i would like to approval from @eboasson or someone else before merge.

Copy link

@biodranik biodranik left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

The change eliminates dynamic_cast and virtual functions' overhead by using the CRTP pattern https://en.cppreference.com/w/cpp/language/crtp.html

Copy link
Collaborator

@eboasson eboasson left a comment

Choose a reason for hiding this comment

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

LGTM (not that I am much of a C++ programmer)

Merging this is going to require some rework on #550. For that I only took the existing code and added a few variations and a few functions, so I am hopeful it is straightforward. The trouble is that I don't really know whether my hope is well-founded ("I am not much of a ..." &c.). Perhaps you could check @jmachowinski ?

@jmachowinski
Copy link
Contributor Author

I can go over #550 and do the hardcore optimization part there...
@eboasson as you are fine with this PR, I'll merge it now and also create the backports.

@jmachowinski jmachowinski merged commit 5147e01 into ros2:rolling Feb 19, 2026
2 checks passed
@jmachowinski
Copy link
Contributor Author

jmachowinski commented Feb 19, 2026

@Mergifyio backport jazzy kilted

@mergify
Copy link

mergify bot commented Feb 19, 2026

backport jazzy kilted

✅ Backports have been created

Details

mergify bot pushed a commit that referenced this pull request Feb 19, 2026
* perf: Fixed high CPU usage due to dynamic_cast

The dynamic_cast here turned out to be quite costly. Replacing
it by the variant like function, we see a ~10% cpu usage reduction
in our use case.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>

* perf: Replaced virtual functions by templates

This gives another performance improvement of around 2% of cpu
usage in our usage scenario.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>

---------

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
Co-authored-by: Janosch Machowinski <J.Machowinski@cellumation.com>
(cherry picked from commit 5147e01)
mergify bot pushed a commit that referenced this pull request Feb 19, 2026
* perf: Fixed high CPU usage due to dynamic_cast

The dynamic_cast here turned out to be quite costly. Replacing
it by the variant like function, we see a ~10% cpu usage reduction
in our use case.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>

* perf: Replaced virtual functions by templates

This gives another performance improvement of around 2% of cpu
usage in our usage scenario.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>

---------

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
Co-authored-by: Janosch Machowinski <J.Machowinski@cellumation.com>
(cherry picked from commit 5147e01)
jmachowinski added a commit that referenced this pull request Feb 20, 2026
* perf: Fixed high CPU usage due to dynamic_cast

The dynamic_cast here turned out to be quite costly. Replacing
it by the variant like function, we see a ~10% cpu usage reduction
in our use case.



* perf: Replaced virtual functions by templates

This gives another performance improvement of around 2% of cpu
usage in our usage scenario.



---------



(cherry picked from commit 5147e01)

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
Co-authored-by: Janosch Machowinski <jmachowinski@users.noreply.github.com>
Co-authored-by: Janosch Machowinski <J.Machowinski@cellumation.com>
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.

4 participants