ElinamLLC / SharpVectors

SharpVectors - SVG# Reloaded: SVG DOM and Rendering in C# for the .Net.
https://elinamllc.github.io/SharpVectors/
BSD 3-Clause "New" or "Revised" License
719 stars 136 forks source link

Reduce drastically allocation rate when parsing CSS Colors. #239

Closed ciplogic closed 1 year ago

ciplogic commented 1 year ago

It reduces allocation rate by creating a span like construct, so when moving to .Net (aka Core), this code would have most of functionality to port to it.

paulushub commented 1 year ago

Thanks for the contribution. Using conditional compilation, can you add the .Net Core ports?

ciplogic commented 1 year ago

Hello, I have a question Paul and I will make it over this week (sorry to not answer yesterday, but I was with my family).

So let' me understand you as your comment can be addressed in 2 ways:

Which one would it be more convenient?

As for a timeline: I will contribute it over this week time I assume, as I do it over my free time.

As for this Merge Request: works in Net Core unmodified, just it doesn't get the Span related JIT improvements.

paulushub commented 1 year ago

add reference to System.Memory

Yes, it is .NET4.6.1+, .NET-Std 1.1+. 2.0+

add a .Net Core only Span implementation with no external references. Yes, the implementation is up to you.

As for a timeline: I will contribute it over this week time I assume, as I do it over my free time.

Anytime is fine. I have committed the current implementation and could make it available in Nuget package if you need it.

ciplogic commented 1 year ago

Thank you Paul!

My company is using SharpVectors and I thought to contribute back (I am not getting any paycheck out of it), as this is an ethical way to do it.

As for NuGet bump, I will want to profile a bit more the code, and see if I can see other perf issues (if any I can see with my time), and maybe in 1 month time frame, I can ask you for a bump.

So maybe around New Year's time (of course, if you are in holidays, it can be after holidays).

Sayonara!

ciplogic commented 1 year ago

I tried to port to Span and I noticed that are few parts I cannot do it, especially Split() as it requires heap creation of slices.

I also profiled more, and right now the memory consumption is around Regex, so even if I could circumvent and find a nice way to do the spans, it may not worth the effort.

paulushub commented 1 year ago

@ciplogic Thanks for the efforts.

I also profiled more, and right now the memory consumption is around Regex...

The extensive use of the Regex is one of the problems inherited from SharpVectorGraphics. I have started a new project privately to create a new library, but cannot easily find the time - mostly doing Python, Java and C++ stuff.