Drawaes / TrimDB

MIT License
54 stars 8 forks source link

Consider skip locals init for stackalloc heavy methods #6

Closed azhmur closed 4 years ago

azhmur commented 4 years ago

While C# feature not yet available https://github.com/dotnet/csharplang/issues/1738 fody plugin can be used: https://github.com/ltrzesniewski/LocalsInit.Fody and it has significant effect for stackalloc heavy methods https://github.com/azhmur/PooledMemoryStream/raw/master/perf.png?raw=true

PS Found your issue as well https://github.com/dotnet/csharplang/issues/868

Drawaes commented 4 years ago

Yes I was actually looking at the init locals issue last night, as it won't be available until .net 5 and I would like this lib to be available to lower .net versions I am Keen to use fody for it instead.

Do you think you are up for a PR ? If not that is cool and I will look into it in the near future after I finish off a couple of other bits.

azhmur commented 4 years ago

Yes, I will, only two stackalloc right now.

Drawaes commented 4 years ago

Yeah, but I suspect that are causing a fair amount of perf impact on the puts.

azhmur commented 4 years ago

Tried to run without initialization, and it fails with memory fault.

https://github.com/Drawaes/TrimDB/blob/master/src/TrimDB.Core/TrimDB.Core/SkipList/SkipList.cs#L56

Checks zero and thus require initialization. I think it may be replaced with different condition, which won't require initialization, but i don't get all the picture behind this code unfortunately.

Drawaes commented 4 years ago

if you put it in a branch i can take a look and see what i can do

azhmur commented 4 years ago

Seems to be fixed for newer sources. But no performance difference observed with or without locals init.