Skip to content

Pre-allocate rclcpp::Time's in the main loop#640

Closed
AndyZe wants to merge 1 commit intoros-controls:masterfrom
AndyZe:andyz/preallocate_times
Closed

Pre-allocate rclcpp::Time's in the main loop#640
AndyZe wants to merge 1 commit intoros-controls:masterfrom
AndyZe:andyz/preallocate_times

Conversation

@AndyZe
Copy link
Copy Markdown
Contributor

@AndyZe AndyZe commented Feb 10, 2022

This is probably a negligible performance improvement but I guess it doesn't hurt.

Copy link
Copy Markdown
Member

@aprotyas aprotyas left a comment

Choose a reason for hiding this comment

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

No strong opinion, but I think the code was more readable before this change, since begin_last and end are polluting the outer scope now. Compilers are probably good with optimizing these in-loop definitions too.

@AndyZe
Copy link
Copy Markdown
Contributor Author

AndyZe commented Feb 11, 2022

Well, I'm not big on trusting compilers so I dropped some benchmarking code in. Basically it adds up the duration of the loop internals minus the sleep() for 10k iterations (attached). I did 10 runs with the status quo vs 10 runs with this PR, ABAB style.

Basically there was no difference. However, I still think we should merge the PR because this is one of the most critical bits of code and it feels weird to depend on compiler optimization for this critical bit.

benchmark.txt

Copy link
Copy Markdown
Member

@aprotyas aprotyas left a comment

Choose a reason for hiding this comment

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

Basically there was no difference. However, I still think we should merge the PR because this is one of the most critical bits of code and it feels weird to depend on compiler optimization for this critical bit.

Hmm, I think there won't be any maintainability concerns either from moving said variables to the outer scope given how small this file is (and probably will remain). I don't see a strong reason to oppose this then. LGTM

Copy link
Copy Markdown
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

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

Thanks for this nitpick :)

@AndyZe and @aprotyas I would also like to hear your opinion on #645.

@destogl
Copy link
Copy Markdown
Member

destogl commented Feb 16, 2022

closing in favor of #646

@destogl destogl closed this Feb 16, 2022
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