Spanification in RavenDB
We are nearly done with RavenDB 4.1. There are currently a few minor stuff that we are still handling, but we are gearing up to push this to our production systems as part of our usual test matrix. Naturally, this means that we are already thinking about what we should do next.
There is a whole bunch of big ticket items that we want to look at, but the most important of which is the one that is likely to garner very little attention from the outside. We are going to take advantage of the new Span<T> API throughout the product. This is something that I really want to get to, since we have a lot of places where we touch native memory, memory mapped sections and in general pay a lot of attention to manual memory management. There are several cases where we had to copy data from unmanaged memory to managed memory just to make some API happy (I’m looking at you, Stream).
With the Span<T> API, that is no longer required, which means that we can usually just hand a pointer to the network that is mapped directly to a file and reduce the amount of work we need to do significantly. We are also going to also go over the codebase and see where else we can take advantage of this behavior. For example, moving our code to the System.IO.Pipes opens up some really interesting scenarios for simplifications of code and reducing of overhead.
We are going to apply lessons learned about how we actually manage memory and apply them as part of that, so just calling it Span<T> is a bit misleading. The underlying reasoning is that we want to get to simplify both I/O and memory management, which are very closely tied together. This shouldn’t actually matter to users, except that the intent is to improve performance once again.
Comments
Can this turn into a series please? 😀
Very good Oren, can we expect to see a couple of posts with examples of the same pieces of code both pre/post spanification maybe with some stats trown in? That would be very nice!
@Yaniv a series? Damn yes, even better :-) !
+1 on the ongoing series of posts showing where Span and Pipes makes sense in Raven's codebase. I'm still trying to wrap my head around where Span (and Pipes) should be used in a real codebase, seeing some real world examples would help.
Just wanted to add another +1 for requesting a series of Spanification posts with code samples - Span is still new, and real-world usage examples are sorely lacking.
Yaniv, Yes, that is the plan
Sounds like a significant codebase change, I get the heebee jeebies when I consider a major change to big stable systems I have. Its always a relief to just decide to greenfield, but then this comes to mind: https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i/
Peter, Did you see this post? https://ayende.com/blog/183649-A/slides-from-todays-talk I have a presentation on this exact topic
Peter, That said, this is decidedly NOT the same thing. This is a refactoring, possible a major one, but just that. It isn't rebooting the project.
Comment preview