You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve performance of unwrapping .NET objects passed from Python (#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 <lost@losttech.software>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
24
24
- Added argument types information to "No method matches given arguments" message
25
25
- Moved wheel import in setup.py inside of a try/except to prevent pip collection failures
26
26
- Removes PyLong_GetMax and PyClass_New when targetting Python3
27
+
- Improved performance of calls from Python to C#
27
28
- Added support for converting python iterators to C# arrays
28
29
- Changed usage of obselete function GetDelegateForFunctionPointer(IntPtr, Type) to GetDelegateForFunctionPointer<TDelegate>(IntPtr)
29
30
- When calling C# from Python, enable passing argument of any type to a parameter of C# type `object` by wrapping it into `PyObject` instance. ([#881][i881])
0 commit comments