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

Add x64 support #451

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Benchmarks/Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<DelaySign>false</DelaySign>
<SignAssembly>false</SignAssembly>
<DefineConstants>$(DefineContants);CURRENT_VERSION_ONLY;RUN_COMPARISON_BENCHMARKS;FLATSHARP_7_0_0_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineContants);CURRENT_VERSION_ONLY;FLATSHARP_7_0_0_OR_GREATER</DefineConstants>
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<NeedsFlatSharpCompiler>true</NeedsFlatSharpCompiler>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Benchmarks/Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void Main(string[] args)

Job job = Job.ShortRun
.WithAnalyzeLaunchVariance(true)
.WithLaunchCount(7)
.WithLaunchCount(3)
.WithWarmupCount(3)
.WithIterationCount(5)
#if AOT
Expand All @@ -58,14 +58,14 @@ public static void Main(string[] args)
#else
.WithRuntime(CoreRuntime.Core80)
#endif
;
;

// job = job.WithEnvironmentVariable(new EnvironmentVariable("DOTNET_TieredPGO", "0"));

var config = DefaultConfig.Instance
.AddColumn(new[] { StatisticColumn.P25, StatisticColumn.P95 })
.AddDiagnoser(MemoryDiagnoser.Default)
.AddJob(job);
.AddJob(job.DontEnforcePowerPlan());

summaries.Add(BenchmarkRunner.Run(typeof(FBBench.FBSerializeBench), config));
summaries.Add(BenchmarkRunner.Run(typeof(FBBench.FBDeserializeBench), config));
Expand Down
26 changes: 13 additions & 13 deletions src/Benchmarks/Benchmark/Serializers/FlatSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal class FlatSharpHelper
private static FS.SortedVectorContainer sortedInts;
private static FS.SortedVectorContainer unsortedInts;

public static int Prepare(int length)
public static long Prepare(int length)
{
BenchmarkUtilities.Prepare(length, out container);
buffer = new byte[GetMaxSize()];
int bytesWritten = Serialize();
long bytesWritten = Serialize();

sortedStrings = new() { SortedStrings = new List<SortedVectorStringKey>() };
unsortedStrings = new() { UnsortedStrings = new List<SortedVectorStringKey>() };
Expand All @@ -41,14 +41,14 @@ public static int Prepare(int length)
return bytesWritten;
}

public static int GetMaxSize()
public static long GetMaxSize()
{
return FS.FooBarContainer.Serializer.GetMaxSize(container);
}

public static int Serialize()
public static long Serialize()
{
return FS.FooBarContainer.Serializer.Write(new SpanWriter(), buffer, container);
return FS.FooBarContainer.Serializer.Write(buffer, container);
}

public static int ParseAndTraverse(int iterations, FlatBufferDeserializationOption option)
Expand All @@ -63,15 +63,15 @@ public static int ParseAndTraversePartial(int iterations, FlatBufferDeserializat
return BenchmarkUtilities.TraverseFooBarContainerPartial(parsed, iterations);
}

public static int SerializeSortedStrings()
=> FS.SortedVectorContainer.Serializer.Write(new SpanWriter(), buffer, sortedStrings);
public static long SerializeSortedStrings()
=> FS.SortedVectorContainer.Serializer.Write(buffer, sortedStrings);

public static int SerializeUnsortedStrings()
=> FS.SortedVectorContainer.Serializer.Write(new SpanWriter(), buffer, unsortedStrings);
public static long SerializeUnsortedStrings()
=> FS.SortedVectorContainer.Serializer.Write(buffer, unsortedStrings);

public static int SerializeSortedInts()
=> FS.SortedVectorContainer.Serializer.Write(new SpanWriter(), buffer, sortedInts);
public static long SerializeSortedInts()
=> FS.SortedVectorContainer.Serializer.Write(buffer, sortedInts);

public static int SerializeUnsortedInts()
=> FS.SortedVectorContainer.Serializer.Write(new SpanWriter(), buffer, unsortedInts);
public static long SerializeUnsortedInts()
=> FS.SortedVectorContainer.Serializer.Write(buffer, unsortedInts);
}
8 changes: 4 additions & 4 deletions src/Benchmarks/Benchmark/Serializers/FlatSharpValueStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ internal class FlatSharpValueStructs
private static byte[] buffer;
private static FS.FooBarContainerValue container;

public static int Prepare(int length)
public static long Prepare(int length)
{
BenchmarkUtilities.Prepare(length, out container);
buffer = new byte[GetMaxSize()];
return Serialize();
}

public static int GetMaxSize()
public static long GetMaxSize()
{
return FS.FooBarContainerValue.Serializer.GetMaxSize(container);
}

public static int Serialize()
public static long Serialize()
{
return FS.FooBarContainerValue.Serializer.Write(new SpanWriter(), buffer, container);
return FS.FooBarContainerValue.Serializer.Write(buffer, container);
}

public static int ParseAndTraverse(int iterations, FlatBufferDeserializationOption option)
Expand Down
20 changes: 19 additions & 1 deletion src/Benchmarks/MicroBench.Current/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microbench
using System.Linq;
using FlatSharp;
using FlatSharp.Internal;
using Microsoft.Diagnostics.Tracing.Parsers.FrameworkEventSource;

public static class Constants
{
Expand Down Expand Up @@ -61,6 +62,22 @@ public static class PrimitiveTables
Float = 1,
Double = 1,
};

public static NestedTable RandomEntries = new()
{
Tables = Enumerable.Range(0, 1000).Select(i => new PrimitivesTable
{
Bool = Random.Shared.Next() % 2 == 0,
Byte = (byte)(Random.Shared.Next() % 2),
SByte = (sbyte)(Random.Shared.Next() % 2),
Short = (short)(Random.Shared.Next() % 2),
UShort = (ushort)(Random.Shared.Next() % 2),
Int = (int)(Random.Shared.Next() % 2),
UInt = (uint)(Random.Shared.Next() % 2),
Long = (long)(Random.Shared.Next() % 2),
ULong = (ulong)(Random.Shared.Next() % 2),
}).ToArray(),
};
}

public static class StructTables
Expand Down Expand Up @@ -155,6 +172,7 @@ public static class Buffers

public static readonly byte[] PrimitivesTable_Empty = AllocateAndSerialize(PrimitiveTables.Empty);
public static readonly byte[] PrimitivesTable_Full = AllocateAndSerialize(PrimitiveTables.Full);
public static readonly byte[] PrimitivesTable_RandomEntries = AllocateAndSerialize(PrimitiveTables.RandomEntries);

public static readonly byte[] StructTable_SingleRef = AllocateAndSerialize(StructTables.SingleRef);
public static readonly byte[] StructTable_SingleValue = AllocateAndSerialize(StructTables.SingleValue);
Expand All @@ -169,7 +187,7 @@ public static class Buffers
private static byte[] AllocateAndSerialize<T>(T value) where T : class, IFlatBufferSerializable<T>
{
byte[] buffer = new byte[value.Serializer.GetMaxSize(value)];
int length = value.Serializer.Write(buffer, value);
long length = value.Serializer.Write(buffer, value);

return buffer;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Benchmarks/MicroBench.Current/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static void Main(string[] args)
.WithLaunchCount(1)
.WithWarmupCount(3)
.WithIterationCount(6)
.WithRuntime(CoreRuntime.Core70);
.WithRuntime(CoreRuntime.Core80)
.DontEnforcePowerPlan();

//.WithEnvironmentVariable(new EnvironmentVariable("DOTNET_TieredPGO", "1"));

var config = DefaultConfig.Instance
Expand Down
30 changes: 18 additions & 12 deletions src/Benchmarks/MicroBench.Current/SerializeBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,73 +24,79 @@ namespace Microbench
public class SerializeBenchmarks
{
[Benchmark]
public int Serialize_StringTable_SingleString()
public long Serialize_StringTable_SingleString()
{
return StringTable.Serializer.Write(Constants.Buffers.StringTable_WithString, Constants.StringTables.WithString);
}

[Benchmark]
public int Serialize_StringTable_Vector()
public long Serialize_StringTable_Vector()
{
return StringTable.Serializer.Write(Constants.Buffers.StringTable_WithVector, Constants.StringTables.WithVector);
}

[Benchmark]
public int Serialize_StringTable_EmptyTable()
public long Serialize_StringTable_EmptyTable()
{
return StringTable.Serializer.Write(Constants.Buffers.Stringtable_Empty, Constants.StringTables.Empty);
}

[Benchmark]
public int Serialize_PrimitivesTable_Empty()
public long Serialize_PrimitivesTable_Empty()
{
return PrimitivesTable.Serializer.Write(Constants.Buffers.PrimitivesTable_Empty, Constants.PrimitiveTables.Empty);
}

[Benchmark]
public int Serialize_PrimitivesTable_Full()
public long Serialize_PrimitivesTable_Full()
{
return PrimitivesTable.Serializer.Write(Constants.Buffers.PrimitivesTable_Full, Constants.PrimitiveTables.Full);
}

[Benchmark]
public int Serialize_StructTable_SingleRef()
public long Serialize_PrimitivesTable_RandomlyPopulated()
{
return NestedTable.Serializer.Write(Constants.Buffers.PrimitivesTable_RandomEntries, Constants.PrimitiveTables.RandomEntries);
}

[Benchmark]
public long Serialize_StructTable_SingleRef()
{
return StructsTable.Serializer.Write(Constants.Buffers.StructTable_SingleRef, Constants.StructTables.SingleRef);
}

[Benchmark]
public int Serialize_StructTable_SingleValue()
public long Serialize_StructTable_SingleValue()
{
return StructsTable.Serializer.Write(Constants.Buffers.StructTable_SingleValue, Constants.StructTables.SingleValue);
}

[Benchmark]
public int Serialize_StructTable_VecRef()
public long Serialize_StructTable_VecRef()
{
return StructsTable.Serializer.Write(Constants.Buffers.StructTable_VecRef, Constants.StructTables.VectorRef);
}

[Benchmark]
public int Serialize_StructTable_VecValue()
public long Serialize_StructTable_VecValue()
{
return StructsTable.Serializer.Write(Constants.Buffers.StructTable_VecValue, Constants.StructTables.VectorValue);
}

[Benchmark]
public int Serialize_SafeUnion()
public long Serialize_SafeUnion()
{
return UnionTable.Serializer.Write(Constants.Buffers.UnionTable_Safe, Constants.UnionTables.Safe);
}

[Benchmark]
public int Serialize_UnsafeUnion()
public long Serialize_UnsafeUnion()
{
return UnionTable.Serializer.Write(Constants.Buffers.UnionTable_Unsafe, Constants.UnionTables.Unsafe);
}

[Benchmark]
public int Serialize_MixedUnion()
public long Serialize_MixedUnion()
{
return UnionTable.Serializer.Write(Constants.Buffers.UnionTable_Mixed, Constants.UnionTables.Mixed);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Benchmarks/Microbench.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ table PrimitivesTable (fs_serializer:"Lazy") {
Float : float;
}

table NestedTable (fs_serializer:"Lazy") {
Tables : [ PrimitivesTable ];
}

struct RefStruct (fs_writeThrough) { Value : int; }
struct ValueStruct (fs_valueStruct) { Value : int; }

Expand All @@ -51,7 +55,6 @@ table SortedTable (fs_serializer:"Lazy")
Ints : [IntKey] (fs_vector:"IIndexedVector");
}


struct ValueStructA (fs_valueStruct) { x : int; }
struct ValueStructB (fs_valueStruct) { y : long; }
struct ValueStructC (fs_valueStruct) { a : ValueStructA; b : ValueStructB; }
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<SignAssembly Condition=" '$(SignAssembly)' == '' ">true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\..\misc\strongname.snk</AssemblyOriginatorKeyFile>
<LangVersion>12.0</LangVersion>
<LangVersion>preview</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CS8032</NoWarn>
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
Expand Down
7 changes: 5 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
<PackageVersion Include="Grpc.Core.Api" Version="2.61.0" />
<PackageVersion Include="Grpc.Tools" Version="2.62.0" />
<PackageVersion Include="MessagePack" Version="2.5.187" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-3.final" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.9.2" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.12.0-3.final">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="1.0.2" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.9.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/FlatSharp.Runtime/BufferTooSmallException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public BufferTooSmallException() : base($"The provided buffer was too small to h
/// <summary>
/// The maximum amount of size needed for this message.
/// </summary>
public int SizeNeeded { get; internal set; }
public long SizeNeeded { get; internal set; }
}
2 changes: 1 addition & 1 deletion src/FlatSharp.Runtime/FSThrow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static T Argument<T>(string message)
#region BufferTooSmall

[DoesNotReturn]
public static void BufferTooSmall(int sizeNeeded)
public static void BufferTooSmall(long sizeNeeded)
{
throw new BufferTooSmallException
{
Expand Down
14 changes: 14 additions & 0 deletions src/FlatSharp.Runtime/FlatSharp.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<DebugType>embedded</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
Expand All @@ -17,6 +18,10 @@
</PropertyGroup>

<ItemGroup>
<None Update="IO\SerializationTarget\BigSpanHelpers.tt">
<LastGenOutput>BigSpanHelpers.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>
<None Update="SpanComparers.tt">
<LastGenOutput>SpanComparers.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
Expand All @@ -32,6 +37,11 @@
</ItemGroup>

<ItemGroup>
<Compile Update="IO\SerializationTarget\BigSpanHelpers.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>BigSpanHelpers.tt</DependentUpon>
</Compile>
<Compile Update="SpanComparers.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand All @@ -43,4 +53,8 @@
<DependentUpon>UnionTypes.tt</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
Loading
Loading