Improve performance of unwrapping .NET objects passed from Python#930
Merged
filmor merged 13 commits intopythonnet:masterfrom May 16, 2020
Merged
Improve performance of unwrapping .NET objects passed from Python#930filmor merged 13 commits intopythonnet:masterfrom
filmor merged 13 commits intopythonnet:masterfrom
Conversation
This addresses the following scenario: 1. A C# object `a` is created and filled with some data. 2. `a` is passed via Python.NET to Python. To do that Python.NET creates a wrapper object `w`, and stores reference to `a` in one of its fields. 3. Python code later passes `w` back to C#, e.g. calls `SomeCSharpMethod(w)`. 4. Python.NET has to unwrap `w`, so it reads the reference to `a` from it. Prior to this change in 4. Python.NET had to determine what kind of an object `a` is. If it is an exception, a different offset needed to be used. That check was very expensive (up to 4 calls into Python interpreter). This change replaces that check with computing offset unconditionally by subtracting a constant from the object size (which is read from the wrapper), thus avoiding calls to Python interpreter.
2dea84a to
39add65
Compare
Codecov Report
@@ Coverage Diff @@
## master #930 +/- ##
==========================================
- Coverage 86.66% 86.33% -0.34%
==========================================
Files 1 1
Lines 300 300
==========================================
- Hits 260 259 -1
- Misses 40 41 +1
Continue to review full report at Codecov.
|
Member
Member
Author
|
Sorry for the delay, cherry-picking didn't work (I assume the given commit is not in any of the branches on the main fork). |
Member
|
Hm, it shows in this fork. This is a very small change though, you can copy it manually. |
Member
Author
|
I did (just before commenting ;)). |
lostmsu
approved these changes
Mar 9, 2020
lostmsu
added a commit
to losttech/pythonnet
that referenced
this pull request
Jun 15, 2020
…ed in Lost Tech branch )
AlexCatarino
pushed a commit
to QuantConnect/pythonnet
that referenced
this pull request
Jun 29, 2020
…thonnet#930) This addresses the following scenario: 1. A C# object `a` is created and filled with some data. 2. `a` is passed via Python.NET to Python. To do that Python.NET creates a wrapper object `w`, and stores reference to `a` in one of its fields. 3. Python code later passes `w` back to C#, e.g. calls `SomeCSharpMethod(w)`. 4. Python.NET has to unwrap `w`, so it reads the reference to `a` from it. Prior to this change in 4. Python.NET had to determine what kind of an object `a` is. If it is an exception, a different offset needed to be used. That check was very expensive (up to 4 calls into Python interpreter). This change replaces that check with computing offset unconditionally by subtracting a constant from the object size (which is read from the wrapper), thus avoiding calls to Python interpreter. Co-authored-by: Victor Milovanov <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstreams QuantConnect#31 by @lostmsu.
Comment by the author:
This addresses the following scenario:
ais created and filled with some data.ais passed via Python.NET to Python. To do that Python.NET creates a wrapper objectw, and stores reference toain one of its fields.wback to C#, e.g. callsSomeCSharpMethod(w).w, so it reads the reference toafrom it.Prior to this change in 4. Python.NET had to determine what kind of an object
ais. If it is an exception, a different offset needed to be used. That check was very expensive (up to 4 calls into Python interpreter).This change replaces that check with computing offset unconditionally by subtracting a constant from the object size (which is read from the wrapper), thus avoiding calls to Python interpreter.