Sharpify.Data
2.6.0
dotnet add package Sharpify.Data --version 2.6.0
NuGet\Install-Package Sharpify.Data -Version 2.6.0
<PackageReference Include="Sharpify.Data" Version="2.6.0" />
paket add Sharpify.Data --version 2.6.0
#r "nuget: Sharpify.Data, 2.6.0"
// Install Sharpify.Data as a Cake Addin #addin nuget:?package=Sharpify.Data&version=2.6.0 // Install Sharpify.Data as a Cake Tool #tool nuget:?package=Sharpify.Data&version=2.6.0
CHANGELOG
v2.6.0
- Updated to support NET9
- Updated to use
Sharpify 2.5.0
andMemoryPack 1.21.3
- All
byte[]
value returning reads from the database, now returnReadOnlyMemory<byte>
instead, previously, to maintain the integrity of the value, a copy was made and returned, because there wasn't any guarantee against modification,ReadOnlyMemory<byte>
enforced this guarantee without creating a copy, if you just reading the data this is much more performant, and if you want to modify it, you can always create a copy at your own discretion. - Decreased memory allocations for the
Func
basedRemove
method. - Removed compiler directions that potentially could not allow the JIT compiler to perform Dynamic PGO.
Upsert{T}
overloads now have aFunc<T, bool> updateCondition
parameter that can be used to ensure that a condition is met before being updated, this is a feature of NoSQL databases that protects against concurrent writes overwriting each other. Now you can use this feature inSharpify.Data
as well.- Of course this feature is also available in
UpsertMany{T}
overloads, and also in the overloads of theJsonTypeInfo T
. - To make it easier to see the result, these
Upsert
methods now returnbool
. False
will only be returned IF ALL of the following conditions are met:- Previous value was stored under this key
- The previous value was successfully deserialized with the right type
- The
updateCondition
was not met
- Of course this feature is also available in
Database
now tracks changes (additions, updates, removals) and compares them serialization events, to avoid serialization if no updates occurred since the previous serialization.- This means that you can automate serialization without worrying about potential waste of resources, for example you could omit
SerializeOnUpdate
from theDatabaseConfiguration
, then create a background task that serializes on a given interval for example withSharpify.Routines.Routine
orSharpify.Routines.AsyncRoutine
, and it will only actually serialize if updates occurred. This can significantly improve performance in cases where there are write peaks, but the database is mostly read from.
- This means that you can automate serialization without worrying about potential waste of resources, for example you could omit
- You can now set the
Path
in theDatabaseConfiguration
to an empty string""
to receive an in-memory version of the database. It still has serialization methods, but they don't perform any operations, they are essentially duds. TryReadToRentedBuffer<T> where T : IMemoryPackable<T>
will now be able to retrieve the precise amount of needed space, so the size of the rented buffer will more accurately reflect the size of the data, this should help with dramatically improve performance when dealing with large objects. Before the buffer would've rented a capacity according to the length of the serialized object, meaning that the buffer was x times larger than needed when x is size(object) / size(byte). So the larger was each object, theRentedBufferWriter
size would grow exponentially, now it grows linearly, maximizing efficiency.- And minor optimizations (same as every other release 😜)
Reminder: Workaround for broken NativeAot support from MemoryPack
As of writing this, MemoryPack's NativeAot support is broken, for any type that isn't already in their cached types, the MemoryPackFormatterProvider
uses reflection to get the formatter, which fails in NativeAot.
As a workaround, we need to add the formatters ourselves, to do this, take any 1 static entry point, that activates before the database is loaded, and add this:
// for every T type that relies on MemoryPack for serialization, and their inheritance hierarchy
// This includes types that implement IMemoryPackable (i.e types that are decorated with MemoryPackable)
MemoryPackFormatterProvider.Register<T>();
// If the type is a collection or dictionary use the other corresponding overloads:
MemoryPackFormatterProvider.RegisterCollection<TCollection, TElement>();
// or
MemoryPackFormatterProvider.RegisterDictionary<TDictionary, TKey, TValue>();
// and so on...
// for all overloads check peek the definition of MemoryPackFormatterProvider, or their Github Repo
Note: Make sure you don't create a new static constructor in those types, MemoryPack
already creates those, you will need to find a different entry point.
With this the serializer should be able to bypass the part using reflection, and thus work even on NativeAot.
P.S. The base type of the Database is already registered the same way on its own static constructor.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
-
net8.0
- MemoryPack (>= 1.21.3)
- Sharpify (>= 2.5.0)
-
net9.0
- MemoryPack (>= 1.21.3)
- Sharpify (>= 2.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.6.0 | 79 | 11/13/2024 |
2.5.0 | 83 | 7/30/2024 |
2.4.1 | 84 | 6/3/2024 |
2.4.0 | 82 | 5/30/2024 |
2.3.0 | 125 | 4/17/2024 |
2.2.0 | 132 | 3/2/2024 |
2.1.3 | 114 | 1/25/2024 |
2.1.2 | 103 | 1/25/2024 |
2.1.1 | 107 | 1/25/2024 |
2.1.0 | 127 | 1/25/2024 |
2.0.2 | 103 | 1/23/2024 |
2.0.1 | 104 | 1/22/2024 |
2.0.0 | 99 | 1/20/2024 |
1.1.0 | 116 | 1/15/2024 |
1.0.3 | 125 | 1/8/2024 |
1.0.2 | 130 | 1/5/2024 |
1.0.1 | 124 | 1/4/2024 |
1.0.0 | 120 | 1/4/2024 |