Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep OnData and OnOrderEvent python reference #2809

Conversation

Martin-Molinero
Copy link
Member

Description

  • AlgorithmPythonWrapper will now keep reference to the OnData and
    OnOrderEvent dynamic method, giving a performance improvement ~5%,
    since it does not have to resolve it in each loop.

Master:
162.97 seconds at 44k data points per second. Processing total of 7,092,090 data points.
159.80 seconds at 44k data points per second. Processing total of 7,092,090 data points.
158.17 seconds at 45k data points per second. Processing total of 7,092,090 data points.

Keeping reference to OnData & OnOrderEvent using dynamic (this PR implementation):
151.93 seconds at 47k data points per second. Processing total of 7,092,090 data points.
152.88 seconds at 46k data points per second. Processing total of 7,092,090 data points.
150.67 seconds at 47k data points per second. Processing total of 7,092,090 data points.

Keeping reference to OnData & OnOrderEvent using PyObject and ToPython:
162.33 seconds at 44k data points per second. Processing total of 7,092,090 data points.
161.64 seconds at 44k data points per second. Processing total of 7,092,090 data points.
164.53 seconds at 43k data points per second. Processing total of 7,092,090 data points.

Keeping reference to OnData & OnOrderEvent using PyObject and FromManagedObject:
166.60 seconds at 43k data points per second. Processing total of 7,092,090 data points.
168.73 seconds at 42k data points per second. Processing total of 7,092,090 data points.
160.79 seconds at 44k data points per second. Processing total of 7,092,090 data points.

Related Issue

Closes #2808

Motivation and Context

Python Execution Speed Improvement

Requires Documentation Change

N/A

How Has This Been Tested?

Executed multiple times benchmark algorithm in related issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description or feature-<issue#>-<description>

- `AlgorithmPythonWrapper` will now keep reference to the `OnData` and
`OnOrderEvent` `PyObject` method, giving a performance improvement,
since it does not have to resolve it in each loop.
Copy link
Member

@AlexCatarino AlexCatarino left a comment

Choose a reason for hiding this comment

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

Simple and effective. Thank you!
Let's just add a note that we could extend this pattern to all methods in this call with a GIL, but since OnData and OnOrderEvent are the methods with more hits, the added complexity wouldn't pay-off.

@jaredbroad jaredbroad merged commit 4098550 into QuantConnect:master Jan 9, 2019
@jaredbroad
Copy link
Member

Thank you @Martin-Molinero @AlexCatarino

@jaredbroad
Copy link
Member

In future @Martin-Molinero please post the demo algorithm you used for the optimization in the PR body. This will be especially important when doing focused optimizations - e.g. optimizing 1 hot method invocation.

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.

Keep reference to OnData and OnOrderEvent methods for python algorithms
3 participants