Skip to content

Commit 223d1be

Browse files
Remove Py.AllowThreads due to performance degradation (#108)
* Remove AllowThreads call causing performance hit * Bump to 2.0.49
1 parent d0feb90 commit 223d1be

File tree

5 files changed

+11
-29
lines changed

5 files changed

+11
-29
lines changed

src/perf_tests/Python.PerformanceTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
16-
<PackageReference Include="quantconnect.pythonnet" Version="2.0.48" GeneratePathProperty="true">
16+
<PackageReference Include="quantconnect.pythonnet" Version="2.0.49" GeneratePathProperty="true">
1717
<IncludeAssets>compile</IncludeAssets>
1818
</PackageReference>
1919
</ItemGroup>
@@ -25,7 +25,7 @@
2525
</Target>
2626

2727
<Target Name="CopyBaseline" AfterTargets="Build">
28-
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.48\lib\net9.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
28+
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.49\lib\net9.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
2929
</Target>
3030

3131
<Target Name="CopyNewBuild" AfterTargets="Build">

src/runtime/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
[assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
55
[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
66

7-
[assembly: AssemblyVersion("2.0.48")]
8-
[assembly: AssemblyFileVersion("2.0.48")]
7+
[assembly: AssemblyVersion("2.0.49")]
8+
[assembly: AssemblyFileVersion("2.0.49")]

src/runtime/Python.Runtime.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<RootNamespace>Python.Runtime</RootNamespace>
66
<AssemblyName>Python.Runtime</AssemblyName>
77
<PackageId>QuantConnect.pythonnet</PackageId>
8-
<Version>2.0.48</Version>
8+
<Version>2.0.49</Version>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1010
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1111
<RepositoryUrl>https://github.com/pythonnet/pythonnet</RepositoryUrl>

src/runtime/Types/FieldObject.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,12 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
6464
// Fasterflect does not support constant fields
6565
if (info.IsLiteral && !info.IsInitOnly)
6666
{
67-
using (Py.AllowThreads())
68-
{
69-
result = info.GetValue(null);
70-
}
67+
result = info.GetValue(null);
7168
}
7269
else
7370
{
7471
var getter = self.GetMemberGetter(info.DeclaringType);
75-
using (Py.AllowThreads())
76-
{
77-
result = getter(info.DeclaringType);
78-
}
72+
result = getter(info.DeclaringType);
7973
}
8074

8175
return Converter.ToPython(result, info.FieldType);
@@ -99,20 +93,14 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
9993
// Fasterflect does not support constant fields
10094
if (info.IsLiteral && !info.IsInitOnly)
10195
{
102-
using (Py.AllowThreads())
103-
{
104-
result = info.GetValue(co.inst);
105-
}
96+
result = info.GetValue(co.inst);
10697
}
10798
else
10899
{
109100
var type = co.inst.GetType();
110101
var getter = self.GetMemberGetter(type);
111102
var argument = self.IsValueType(type) ? co.inst.WrapIfValueType() : co.inst;
112-
using (Py.AllowThreads())
113-
{
114-
result = getter(argument);
115-
}
103+
result = getter(argument);
116104
}
117105

118106
return Converter.ToPython(result, info.FieldType);

src/runtime/Types/PropertyObject.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
7777
try
7878
{
7979
var getterFunc = self.GetMemberGetter(info.DeclaringType);
80-
using (Py.AllowThreads())
81-
{
82-
result = getterFunc(info.DeclaringType);
83-
}
80+
result = getterFunc(info.DeclaringType);
8481
return Converter.ToPython(result, info.PropertyType);
8582
}
8683
catch (Exception e)
@@ -97,10 +94,7 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
9794

9895
try
9996
{
100-
using (Py.AllowThreads())
101-
{
102-
result = getter.Invoke(co.inst, Array.Empty<object>());
103-
}
97+
result = getter.Invoke(co.inst, Array.Empty<object>());
10498
return Converter.ToPython(result, info.PropertyType);
10599
}
106100
catch (Exception e)

0 commit comments

Comments
 (0)