From bdc6ccfc806cd94f81cb0502c57b6138c7880fd2 Mon Sep 17 00:00:00 2001 From: jose_morato Date: Thu, 16 Nov 2023 14:49:19 +0100 Subject: [PATCH 01/11] [feature] Improve JSON performance --- .github/workflows/cd_standard.yaml | 2 +- .github/workflows/ci_standard.yaml | 4 +- .../OpenDDSharp.Build.csproj | 2 +- Documentation/articles/introduction.md | 3 ++ .../ConsoleDemoCore/ConsoleDemoCore.csproj | 6 +-- Native/CSharpJsonImplTemplate.txt | 49 ++++++++++--------- README.md | 3 ++ .../OpenDDSharp.BuildTasks.csproj | 6 +-- .../OpenDDSharp.Marshaller.csproj | 5 +- .../IdlProject/OpenDDSharp.IdlProject.csproj | 2 +- Sources/OpenDDSharp/OpenDDSharp.csproj | 8 +-- .../OpenDDSharp.UnitTest.csproj | 8 +-- Tests/TestIdlJson/TestIdlJson.csproj | 5 +- .../TestSupportProcessCore.csproj | 2 +- global.json | 2 +- 15 files changed, 58 insertions(+), 49 deletions(-) diff --git a/.github/workflows/cd_standard.yaml b/.github/workflows/cd_standard.yaml index b7d26a99..03d50674 100644 --- a/.github/workflows/cd_standard.yaml +++ b/.github/workflows/cd_standard.yaml @@ -36,7 +36,7 @@ jobs: - uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' - name: Cache OpenDDS libraries id: opendds-libraries-windows-cd diff --git a/.github/workflows/ci_standard.yaml b/.github/workflows/ci_standard.yaml index 9f6508a4..26520eee 100644 --- a/.github/workflows/ci_standard.yaml +++ b/.github/workflows/ci_standard.yaml @@ -37,10 +37,10 @@ jobs: with: dotnet-version: '6.0.x' - - name: Setup dotnet 7.0 + - name: Setup dotnet 8.0 uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.0.402' + dotnet-version: '8.0.x' # - name: Setup dotnet 6.0 # shell: pwsh diff --git a/Build/OpenDDSharp.Build/OpenDDSharp.Build.csproj b/Build/OpenDDSharp.Build/OpenDDSharp.Build.csproj index a194dc80..81645d5a 100644 --- a/Build/OpenDDSharp.Build/OpenDDSharp.Build.csproj +++ b/Build/OpenDDSharp.Build/OpenDDSharp.Build.csproj @@ -39,7 +39,7 @@ all - + all diff --git a/Documentation/articles/introduction.md b/Documentation/articles/introduction.md index 4b8a4cdd..9da41cb6 100644 --- a/Documentation/articles/introduction.md +++ b/Documentation/articles/introduction.md @@ -73,6 +73,9 @@ The following table shows the Target Frameworks that are already implemented and | net7.0 | :white_check_mark: | | net7.0-android | :x: | | net7.0-ios | :x: | +| net8.0 | :white_check_mark: | +| net8.0-android | :x: | +| net8.0-ios | :x: | The following table shows the Runtimes Identifiers that are already implemented and tested ( :white_check_mark: ) and the ones that are planned for next versions ( :x: ): diff --git a/Examples/ConsoleDemoCore/ConsoleDemoCore.csproj b/Examples/ConsoleDemoCore/ConsoleDemoCore.csproj index 1278d982..f554ef65 100644 --- a/Examples/ConsoleDemoCore/ConsoleDemoCore.csproj +++ b/Examples/ConsoleDemoCore/ConsoleDemoCore.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 x64;x86;ARM64 win-x64;win-x86;linux-x64;osx-x64;osx-arm64 true @@ -30,7 +30,7 @@ all - + all @@ -40,7 +40,7 @@ PreserveNewest - + <_Parameter1>true diff --git a/Native/CSharpJsonImplTemplate.txt b/Native/CSharpJsonImplTemplate.txt index cc77b5c5..d087e00a 100644 --- a/Native/CSharpJsonImplTemplate.txt +++ b/Native/CSharpJsonImplTemplate.txt @@ -1,6 +1,23 @@ public class <%TYPE%>TypeSupport : ITypeSupport<<%TYPE%>> { #region Field + private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions + { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + WriteIndented = false, + AllowTrailingCommas = true, + Converters = + { + new JsonStringEnumConverter(), + new OctetArrayConverter(), + new FloatJsonConverter(), + new DoubleJsonConverter(), + new DecimalJsonConverter(), + }, + }; + + private static readonly <%TYPE%>SerializerContext _serializerContext = new <%TYPE%>SerializerContext(_serializerOptions); + private IntPtr _native; #endregion @@ -29,34 +46,12 @@ public string EncodeToString(<%TYPE%> sample) { - return JsonSerializer.Serialize(sample, new JsonSerializerOptions - { - AllowTrailingCommas = false, - Converters = - { - new JsonStringEnumConverter(), - new OctetArrayConverter(), - new FloatJsonConverter(), - new DoubleJsonConverter(), - new DecimalJsonConverter(), - } - }); + return JsonSerializer.Serialize(sample, typeof(<%TYPE%>), _serializerContext); } public <%TYPE%> DecodeFromString(string str) { - return JsonSerializer.Deserialize<<%TYPE%>>(str, new JsonSerializerOptions - { - AllowTrailingCommas = true, - Converters = - { - new JsonStringEnumConverter(), - new OctetArrayConverter(), - new FloatJsonConverter(), - new DoubleJsonConverter(), - new DecimalJsonConverter(), - } - }); + return JsonSerializer.Deserialize(str, typeof(<%TYPE%>), _serializerContext) as <%TYPE%>; } #endregion @@ -79,6 +74,12 @@ #endregion } + [JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default)] + [JsonSerializable(typeof(<%TYPE%>))] + public partial class <%TYPE%>SerializerContext : JsonSerializerContext + { + } + public class <%TYPE%>DataWriter : DataWriter { #region Fields diff --git a/README.md b/README.md index cf1d2b22..cf61efc5 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,9 @@ The following table shows the Target Frameworks that are already implemented and | net7.0 | :white_check_mark: | | net7.0-android | :x: | | net7.0-ios | :x: | +| net8.0 | :white_check_mark: | +| net8.0-android | :x: | +| net8.0-ios | :x: | The following table shows the Runtimes Identifiers that are already implemented and tested ( :white_check_mark: ) and the ones that are planned for next versions ( :x: ): diff --git a/Sources/OpenDDSharp.BuildTasks/OpenDDSharp.BuildTasks.csproj b/Sources/OpenDDSharp.BuildTasks/OpenDDSharp.BuildTasks.csproj index 4305e37c..50383bbe 100644 --- a/Sources/OpenDDSharp.BuildTasks/OpenDDSharp.BuildTasks.csproj +++ b/Sources/OpenDDSharp.BuildTasks/OpenDDSharp.BuildTasks.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net6.0;net7.0; + netstandard2.0;net6.0;net7.0;net8.0; disable latest ..\..\OpenDDSharpRules.ruleset @@ -10,8 +10,8 @@ - - + + diff --git a/Sources/OpenDDSharp.Marshaller/OpenDDSharp.Marshaller.csproj b/Sources/OpenDDSharp.Marshaller/OpenDDSharp.Marshaller.csproj index 18710659..4a1b2bc5 100644 --- a/Sources/OpenDDSharp.Marshaller/OpenDDSharp.Marshaller.csproj +++ b/Sources/OpenDDSharp.Marshaller/OpenDDSharp.Marshaller.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0; + netstandard2.0;net6.0;net7.0;net8.0; x64;x86;ARM64 Debug;Release ..\..\OpenDDSharpRules.ruleset @@ -13,6 +13,7 @@ OpenDDSharp IDL code generator support classes. + false @@ -33,7 +34,7 @@ - + diff --git a/Sources/OpenDDSharp.Templates/templates/IdlProject/OpenDDSharp.IdlProject.csproj b/Sources/OpenDDSharp.Templates/templates/IdlProject/OpenDDSharp.IdlProject.csproj index 468c4941..377c8384 100644 --- a/Sources/OpenDDSharp.Templates/templates/IdlProject/OpenDDSharp.IdlProject.csproj +++ b/Sources/OpenDDSharp.Templates/templates/IdlProject/OpenDDSharp.IdlProject.csproj @@ -2,7 +2,7 @@ - netstandard2.0;net6.0;net7.0; + netstandard2.0;net6.0;net7.0;net8.0; 7.3 x64;x86 Debug;Release diff --git a/Sources/OpenDDSharp/OpenDDSharp.csproj b/Sources/OpenDDSharp/OpenDDSharp.csproj index 1325e7c9..ecc9c6e6 100644 --- a/Sources/OpenDDSharp/OpenDDSharp.csproj +++ b/Sources/OpenDDSharp/OpenDDSharp.csproj @@ -2,7 +2,7 @@ - netstandard2.0;net6.0;net7.0; + netstandard2.0;net6.0;net7.0;net8.0; OpenDDSharp ..\..\OpenDDSharpRules.ruleset x64;x86;ARM64 @@ -39,7 +39,7 @@ 1.0.0 LICENSE.txt - + @@ -57,7 +57,7 @@ all - + all @@ -71,7 +71,7 @@ - + diff --git a/Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj b/Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj index 3d0ae844..2fe801b1 100644 --- a/Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj +++ b/Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj @@ -2,8 +2,8 @@ true - net462;net47;net471;net472;net48;net6.0;net7.0; - net6.0;net7.0; + net462;net47;net471;net472;net48;net6.0;net7.0;net8.0; + net6.0;net7.0;net8.0; false ..\..\OpenDDSharpRules.ruleset true @@ -54,7 +54,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -77,7 +77,7 @@ all - + all diff --git a/Tests/TestIdlJson/TestIdlJson.csproj b/Tests/TestIdlJson/TestIdlJson.csproj index 23f6cc88..5b6c1f12 100644 --- a/Tests/TestIdlJson/TestIdlJson.csproj +++ b/Tests/TestIdlJson/TestIdlJson.csproj @@ -1,8 +1,8 @@  - netstandard2.0;net6.0;net7.0; - 7.3 + netstandard2.0;net6.0;net7.0;net8.0; + latest x64;x86;ARM64 Debug;Release