Comments (10)
Ah, yeah, didn't consider this. I'll take a deeper look. My first idea was a First-in/First-out when reaching max. size.
(Existing type cache is also implemented as simple dictionary.)
from yaxlib.
Just ported https://github.com/NLog/NLog/blob/dev/src/NLog/Internal/Collections/MruCache.cs - looks good. I think I'm gonna go for thatπ
from yaxlib.
Got it working with an YAXSerializer
object pool.
Results are promising - about 6x faster with 6x less GC pressure compared to the current v4 branch:
| Method | N | Mean | Error | StdDev | Gen 0 | Allocated |
|-------------------------- |----- |----------:|---------:|---------:|----------:|----------:|
| NoPool_NoWrapperCache_V4 | 500 | 83.19 ms | 0.941 ms | 0.834 ms | 4000.0000 | 35 MB |
| NoPool_NoWrapperCache_V4 | 1000 | 164.48 ms | 1.682 ms | 1.573 ms | 8000.0000 | 71 MB |
|-------------------------- |----- |----------:|---------:|---------:|----------:|----------:|
| With_Pool_WrapperCache | 500 | 14.12 ms | 0.281 ms | 0.438 ms | - | 6 MB |
| With_Pool_WrapperCache | 1000 | 28.84 ms | 0.561 ms | 0.690 ms | 1000.0000 | 13 MB |
Cache and Pool both have limits in size now. Actually, the pool is rather small: only 12 items across all unit tests, but used with a high frequency.
from yaxlib.
@304NotModified After having the MemberWrapperCache
working, this looks quite nice already:
// * Summary *
BenchmarkDotNet=v0.13.0, OS=Windows 10.0.22000
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK=6.0.301
[Host] : .NET 6.0.6 (6.0.622.26707), X64 RyuJIT
.NET 6.0 : .NET 6.0.6 (6.0.622.26707), X64 RyuJIT
Job=.NET 6.0 Runtime=.NET 6.0
| Method | N | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|-------------------------- |---- |---------:|---------:|---------:|----------:|--------:|------:|----------:|
| WithMemberWrapperCache | 100 | 4.06 ms | 0.075 ms | 0.070 ms | 437.5000 | 7.8125 | - | 4 MB |
| WithoutMemberWrapperCache | 100 | 17.77 ms | 0.350 ms | 0.327 ms | 1125.0000 | 62.5000 | - | 9 MB |
This is includes creating a new YAXSerializer
instance in each iteration:
[Benchmark(Baseline = false)]
public void WithoutMemberWrapperCache()
{
for (var i = 0; i < N; i++)
{
_serializer = new YAXSerializer(typeof(YAXLibTests.SampleClasses.MoreComplexExample), new SerializerOptions {
ExceptionHandlingPolicies = YAXExceptionHandlingPolicies.DoNotThrow,
ExceptionBehavior = YAXExceptionTypes.Warning,
SerializationOptions = YAXSerializationOptions.SerializeNullObjects
});
_ = _serializer.Serialize(_sampleClass);
}
}
When iterating with only one class variable instance, speed drops with every iteration and memory consumption goes up. Even N = 100 takes ages to complete. Running the sample as unit tests completed fast, though. Sth. wrong with the performance test test setup, I guess.
from yaxlib.
Cool stuff. But is there a max cache size? Or what happens if there is a memory shortage?
from yaxlib.
No, currently there is no max cache size. This has no issues even after running all unit tests, where all class members go to the static cache. Didn't check yet how big it is then. You think the cache size should be limited?
from yaxlib.
Yes otherwise you could get memory leaks or out of memory issues.
from yaxlib.
Maybe we could do something with https://docs.microsoft.com/en-us/dotnet/core/extensions/caching
Or https://github.com/NLog/NLog/blob/dev/src/NLog/Internal/Collections/MruCache.cs (also tests there)
from yaxlib.
@304NotModified Just checked the number of recursions that happen across all unit tests and using method YAXSerializer.NewInternalSerializer
With every counted recursion, a new YAXSerializer
is created.
A YAXSerializerPool
might bring a gain in speed and less GC pressure, wouldn't it?
After a first trial this seems not so easy to implement...
Group Count
9 Recursions = 110168
8 Recursions = 326
7 Recursions = 2293
6 Recursions = 126
5 Recursions = 963
4 Recursions = 26
3 Recursions = 52
2 Recursions = 168
1 Recursion = 1106
Total Count = 115228
from yaxlib.
Resolved with release v4.0.0
from yaxlib.
Related Issues (20)
- Dictionary serialization incorrect when publishing to single file HOT 4
- Generic deserialization methods should not hide base methods with 'new', e.g. with a generic base class HOT 1
- Possible regression caused by PR #183 HOT 9
- Extend tests to cover YAXSerializer and YAXSerializer<T> HOT 2
- Split IYAXSerializer<T> to IYAXSerializer<T> and IYAXDeserializer<T> HOT 7
- Make Exception a KnownType HOT 4
- All public members of YAXSerializer (generic/non-generic) should be fully covered by unit tests HOT 1
- How serialize a list as an attribute HOT 7
- Extend SerializationContext for pre-processing in ICustomSerializer and IKnownType
- Add unit tests for YAXCollectionItemTypeAttribute and YAXElementForAttribute
- Add YAXSerializationOptions.StripInvalidXmlChars HOT 3
- Structs are not serialized correctly HOT 3
- Update docs for new v4 features
- Multiple Elements with Same Name? How to Deserialize?
- Add support for DateOnly and TimeOnly types
- Is it possible deserialize to property by attribute name and inner xml with YAXLib?
- Serializing/Deserializing ValueTuples HOT 1
- Serialize not filtering properties correctly in .NET Standard HOT 6
- Serialized strings that use the stringbuilder pool throw when the string's length is > 1024 (DefaultStringBuilderCapacity).
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaxlib.