CoreyKaylor / Lightning.NET

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

.NET 7 Improvements & Request For Ideas #156

Open CoreyKaylor opened 1 year ago

CoreyKaylor commented 1 year ago

I'm catching up on some of the improvements made over the last few versions of .NET. I noticed that 7 has a new LibraryImport attribute that I could possibly leverage. What other things should I consider for this library? Open to hearing all ideas, but I'm keenly interested in the lower level items that this library will benefit from as-is.

Regardless of how much is taken on. I'm likely to release one more version for netstandard that has the latest 0.9.29 binaries included for all supported runtimes. After that I'm likely to drop support for netstandard and focus only on newer runtimes going forward. How do others feel about this?

CoreyKaylor commented 1 year ago

I've opened https://github.com/CoreyKaylor/Lightning.NET/pull/158 with my initial pass at these improvements.

AlgorithmsAreCool commented 1 year ago

There are probably some hygiene features we can use such as more nullable annotations and use of the scoped keyword on stackallocated buffers.

CoreyKaylor commented 1 year ago

What would scoped keyword buy us in this case? I'm not too familiar with the latest changes there.

AlgorithmsAreCool commented 1 year ago

Probably not a ton? It has to do with escape semantics of ref-like types such as Span since they can use stackallocated memory that is invalid if passed back to parent frames. I'd need to eyeball the code to see if we bother with that anywhere. But it is a new language safety feature.

Now that i'm thinking about it, it might be worth running some performance experiments with new runtime features. In the past I've seen other high-performance libraries use the IL calli instruction to perform low overhead calls, but it wasn't really safe at the time. These days, function pointers can use that instruction in a safe manner and there is also the new-ish CallConvSuppressGCTransition and SuppressGCTransition attribute that might reduce overhead also. But those need careful consideration due to some bad issues they can cause.

CoreyKaylor commented 1 year ago

Interesting, although looking briefly at the docs and it seems they come with some pretty strict requirements.

CoreyKaylor commented 1 year ago

I like the nullable options now for reference types. I've been working on a Kotlin version of LMDB and it brings a very clean API to make it explicit. Once I've made some progress there, I'll circle back on this library to make similar changes.