Skip to content

Generate imports for assert only in debug mode#277

Merged
mikaelarguedas merged 2 commits intoros2:masterfrom
martins-mozeiko:assert-imports
May 24, 2018
Merged

Generate imports for assert only in debug mode#277
mikaelarguedas merged 2 commits intoros2:masterfrom
martins-mozeiko:assert-imports

Conversation

@martins-mozeiko
Copy link
Copy Markdown
Contributor

Reduce amount of imports are executed at runtime by doing them only when python runs in debug mode (PYTHONOPTIMIZE=0). If python runs in optimized mode, assert statements are not executed, but currently there are a lot of imports happening. This patch moves imports inside if __debug__ condition.

This significantly reduces amount of import statements executed at runtime. We have seen significant performance gains on Raspberry Pi 3 when messages contain arrays - because accessing each array element would trigger many imports.

@tfoote tfoote added the in review Waiting for review (Kanban column) label May 15, 2018
@mikaelarguedas mikaelarguedas self-requested a review May 22, 2018 15:51
@mikaelarguedas
Copy link
Copy Markdown
Member

Thanks @martins-mozeiko for the contribution.

I pushed a fixup commit directly on this branch to use 4-space indentation for the Python code.

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Copy Markdown
Member

@mikaelarguedas mikaelarguedas left a comment

Choose a reason for hiding this comment

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

lgtm

@mikaelarguedas mikaelarguedas merged commit cf692c1 into ros2:master May 24, 2018
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label May 24, 2018
@mikaelarguedas
Copy link
Copy Markdown
Member

Thanks @martins-mozeiko for the patch!

@dirk-thomas dirk-thomas mentioned this pull request Oct 25, 2018
34 tasks
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