CoreyKaylor / Lightning.NET

.NET library for LMDB key-value store
Other
399 stars 82 forks source link

Span<T> and Memory<T> #110

Closed AlgorithmsAreCool closed 4 years ago

AlgorithmsAreCool commented 6 years ago

Now that System.Memory is available, .NET has a way to get closer to the 0-copy read/write semantics of LMDB.

Do you think providing Span overloads for operations if a good fit for this library? If so I'd be willing to get some PRs going to support it.

jakoss commented 6 years ago

As far i can tell without compiling code it's all matter of this class https://github.com/CoreyKaylor/Lightning.NET/blob/master/src/LightningDB/Native/ValueStructure.cs

We can add method ReadOnlySpan<byte> GetSpan() with body like this (not tested and even compiled):

public ReadOnlySpan<byte> GetSpan()
{
  return new Span<byte>(data.ToPointer(), size.ToInt32());
}

I think it should work. I'll try to compile this in a free moment and push PR

jakoss commented 6 years ago

I'm not sure if we should expand api with call like "GetSpan" or just override default get? I think main contributors should make that decision

jakoss commented 6 years ago

https://github.com/CoreyKaylor/Lightning.NET/pull/111

jakoss commented 6 years ago

Seems like this repo is quite dead. If you are looking for really performant LMDB adapter use this https://github.com/Spreads/Spreads.LMDB . I'm using it on production. On .NET Core 2.1 (full Span/Memory support) allocations are really rare, it's super awsome. Using it is quite cumbersome (you need to pin everything that talks with database) but it's really worth it

CoreyKaylor commented 4 years ago

Long overdue, but first pass is on master now b048931dc3a. More API changes coming but using Span definitely makes things nicer. No perf comparisons yet.

AlgorithmsAreCool commented 4 years ago

@CoreyKaylor I've got some more free time these days, can i help with anything?

CoreyKaylor commented 4 years ago

@AlgorithmsAreCool I've added a few up for grabs issues. Let me know if you're interested in any of them. Not exhaustive, but those are the immediate ones that come to mind.