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

Improved performance for .NET 9.0+ using the new System.Threading.Lock. #1560

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0'">
<DefineConstants>Core;NET80</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net9.0'">
<DefineConstants>Core;NET90</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net481'">
<DefineConstants>NET481;NETFULL</DefineConstants>
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageVersion Include="Backport.System.Threading.Lock" Version="1.1.1" />
<PackageVersion Include="FakeItEasy" Version="8.0.0" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus.Interfaces/EPPlus.Interfaces.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0;net462;net35</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0;net462;net35</TargetFrameworks>
<AssemblyVersion>6.1.1.0</AssemblyVersion>
<FileVersion>6.1.1.0</FileVersion>
<Version>6.1.1</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus.System.Drawing/EPPlus.System.Drawing.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0;net462;net35</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0;net462;net35</TargetFrameworks>
<AssemblyVersion>6.1.1.0</AssemblyVersion>
<FileVersion>6.1.1.0</FileVersion>
<Version>6.1.1</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/Core/CellStore/CellStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static class CellStoreSettings
/// </summary>
internal class CellStore<T> : IDisposable
{
private readonly static object _syncRoot = new object();
private readonly static Lock _syncRoot = new Lock();
internal ColumnIndex<T>[] _columnIndex;
internal int ColumnCount;
public bool IsReadonly { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus/Core/CellStore/ColumnIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ Date Author Change
*************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;

namespace OfficeOpenXml.Core.CellStore
{
internal class ColumnIndex<T> : IndexBase, IDisposable
{
private readonly static object _syncRoot = new object();
private readonly static Lock _syncRoot = new Lock();
internal List<T> _values = new List<T>();
internal PageIndex[] _pages;
internal int PageCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ Date Author Change
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace OfficeOpenXml.Core.Worksheet.Fonts.GenericFontMetrics
{
internal abstract class GenericFontMetricsTextMeasurerBase
{
private FontScaleFactors _fontScaleFactors = new FontScaleFactors();
private static Dictionary<uint, SerializedFontMetrics> _fonts;
private static object _syncRoot = new object();
private static Lock _syncRoot = new Lock();

public GenericFontMetricsTextMeasurerBase()
{
Expand Down
8 changes: 6 additions & 2 deletions src/EPPlus/EPPlus.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0;net462;net35</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0;net462;net35</TargetFrameworks>
<AssemblyVersion>7.2.2.0</AssemblyVersion>
<FileVersion>7.2.2.0</FileVersion>
<Version>7.2.2</Version>
Expand Down Expand Up @@ -505,7 +505,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>OpenOfficeXml.snk</AssemblyOriginatorKeyFile>
<NeutralLanguage />
<LangVersion>latest</LangVersion>
<LangVersion>preview</LangVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<PackageIcon>EPPlusLogo.png</PackageIcon>
Expand Down Expand Up @@ -565,6 +565,10 @@
<PackageReference Include="System.Text.Encoding.CodePages" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net35' or '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Backport.System.Threading.Lock" />
</ItemGroup>

<ItemGroup>
<Compile Remove="LoadFunctions\HeaderReader.cs" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus/FontSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Date Author Change
using System.IO;
using System.Text;
using OfficeOpenXml.Utils;
using System.Threading;

namespace OfficeOpenXml
{
Expand All @@ -35,7 +36,7 @@ public class FontSize
/// </summary>
public const string NonExistingFont = "Arial";
internal static bool _isLoaded = false;
internal static object _lockObj=new object();
internal static Lock _lockObj = new Lock();
internal static MemoryStream _fontStream=null;
/// <summary>
/// Dictionary containing Font Width in pixels.
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus/FormulaParsing/Excel/Functions/ArgumentParsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Date Author Change
01/27/2020 EPPlus Software AB Initial release EPPlus 5
*************************************************************************************************/
using System.Collections.Generic;
using System.Threading;
using OfficeOpenXml.FormulaParsing.FormulaExpressions;
using OfficeOpenXml.FormulaParsing.Utilities;

Expand All @@ -21,7 +22,7 @@ namespace OfficeOpenXml.FormulaParsing.Excel.Functions
/// </summary>
internal class ArgumentParsers
{
private static object _syncRoot = new object();
private static Lock _syncRoot = new Lock();
private readonly Dictionary<DataType, ArgumentParser> _parsers = new Dictionary<DataType, ArgumentParser>();
private readonly ArgumentParserFactory _parserFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Date Author Change
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using MathObj = System.Math;

namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Engineering
Expand Down Expand Up @@ -80,7 +81,7 @@ public Prefix(string abbrevation, double value)
private static List<Prefix> _metricPrefixes = null;
private static List<Prefix> _binaryPrefixes = null;
private static bool _initialized = false;
private static object _syncRoot = new object();
private static Lock _syncRoot = new Lock();

#region Initialization methods

Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus/FormulaParsing/ExcelAddressCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Date Author Change
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace OfficeOpenXml.FormulaParsing
{
Expand All @@ -21,7 +22,7 @@ namespace OfficeOpenXml.FormulaParsing
/// </summary>
public class ExcelAddressCache
{
private readonly object _myLock = new object();
private readonly Lock _myLock = new Lock();
private readonly Dictionary<int, string> _addressCache = new Dictionary<int, string>();
private readonly Dictionary<string, int> _lookupCache = new Dictionary<string, int>();
private int _nextId = 1;
Expand Down
5 changes: 3 additions & 2 deletions src/EPPlus/Packaging/DotNetZip/WinZipAes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.IO;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Threading;

#if AESCRYPTO
namespace OfficeOpenXml.Packaging.Ionic.Zip
Expand Down Expand Up @@ -310,7 +311,7 @@ internal static string FormatByteArray(byte[] b)
}

#endif
#endregion
#endregion



Expand Down Expand Up @@ -935,7 +936,7 @@ private void TraceOutput(string format, params object[] varParams)
}
}

private object _outputLock = new Object();
private Lock _outputLock = new Lock();
}
}
#endif
3 changes: 2 additions & 1 deletion src/EPPlus/Packaging/DotNetZip/ZipEntry.Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using OfficeOpenXml.Packaging.Ionic.Zlib;
using System;
using System.IO;
using System.Threading;
using RE = System.Text.RegularExpressions;

namespace OfficeOpenXml.Packaging.Ionic.Zip
Expand Down Expand Up @@ -2559,6 +2560,6 @@ private void TraceWriteLine(string format, params object[] varParams)
}
}

private object _outputLock = new Object();
private Lock _outputLock = new Lock();
}
}
3 changes: 2 additions & 1 deletion src/EPPlus/Packaging/DotNetZip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
using System.Reflection;
using Interop = System.Runtime.InteropServices;
using OfficeOpenXml.Packaging.Ionic.Zlib;
using System.Threading;
namespace OfficeOpenXml.Packaging.Ionic.Zip
{
/// <summary>
Expand Down Expand Up @@ -3622,7 +3623,7 @@ private Stream WriteStream
private bool _hasBeenSaved;
private String _TempFileFolder;
private bool _ReadStreamIsOurs = true;
private object LOCK = new object();
private Lock LOCK = new Lock();
private bool _saveOperationCanceled;
private bool _extractOperationCanceled;
private bool _addOperationCanceled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class ParallelDeflateOutputStream : System.IO.Stream
private AutoResetEvent _newlyCompressedBlob;
//private ManualResetEvent _writingDone;
//private ManualResetEvent _sessionReset;
private object _outputLock = new object();
private Lock _outputLock = new Lock();
private bool _isClosed;
private bool _firstWriteDone;
private int _currentlyFilling;
Expand All @@ -121,14 +121,14 @@ public class ParallelDeflateOutputStream : System.IO.Stream
private int _latestCompressed;
private int _Crc32;
private Ionic.Crc.CRC32 _runningCrc;
private object _latestLock = new object();
private Lock _latestLock = new Lock();
private System.Collections.Generic.Queue<int> _toWrite;
private System.Collections.Generic.Queue<int> _toFill;
private Int64 _totalBytesProcessed;
private Ionic.Zlib.CompressionLevel _compressLevel;
private volatile Exception _pendingException;
private bool _handlingException;
private object _eLock = new Object(); // protects _pendingException
private Lock _eLock = new Lock(); // protects _pendingException

// This bitfield is used only when Trace is defined.
//private TraceBits _DesiredTrace = TraceBits.Write | TraceBits.WriteBegin |
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/Utils/RecyclableMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal class RecyclableMemory
{
#if !NET35
private static RecyclableMemoryStreamManager _memoryManager;
private static object _dataLock = new object();
private static Lock _dataLock = new Lock();

public static bool UseRecyclableMemory { get; set; } = true;
internal static bool HasMemoryManager
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/Utils/StreamUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace OfficeOpenXml.Utils
{
internal class StreamUtil
{
static object _lock = new object();
static Lock _lock = new Lock();
/// <summary>
/// Copies the input stream to the output stream.
/// </summary>
Expand Down