-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Ptr
and PtrList
#30
Comments
Hey Tanner - thanks for weighing in here! The primary use-case for Re: Re: Re: I would add a few more options - at least for the primary
|
Using references would definitely resolve my outlined concerns but will mean that either the structure that owns the underlying data is either pinning that data or is unmovable itself while the references exist. Neither of those prospects are particularly appealing to me but I've never felt entirely comfortable making my own pinned data structures maybe that's something you or another contributor have more experience with. Switching to While this appeals to me it isn't the main thing I want to improve. Basically, I don't see anywhere in this library that a call to Cases where we want references but don't need or want interior mutability screams "arena" to me. I have some confidence that we could make using an arena like slotmap or petgraph more performant, ergonomic and robust. But I should probably take a look at where you switched things out previously to better understand the decision. |
Ptr
andPtrList
are useful constructs but they don't exactly match the usage patterns present in this library. I see two problems both relating to the fallible nature of acquiring locks the data:Neither of these are necessarily damning (well, the first more than the second, maybe) but my feeling that they are important is compounded by my perception that we aren't using the interior mutability aspect of a
RwLock
. All of the places that we acquire a write lock are behind a mutable reference already. It seems to me that we're exclusively using the reference counting aspect ofPtr
andPtrList
and not the interior mutability at all. As such, perhaps there is a more applicable abstraction.I also have a sense that if things like the layer maps were modified from outside of the containing data structures there is significant potential for breakage. Or at least it's not clear to me that allowing changes to interior data apart from the API is desired.
Solutions
Replace
std::sync::RwLock
withparking_lot::RwLock
Pros: Low effort.
Cons: Doesn't really fix point 2 but would improve point 1.
Use a slotmap/petgraph
We're representing a directed graph. Petgraph is well used and loved for good reason. This would solve both problems and potentially allow us to leverage existing patterns for traversal and analysis.
Pros: The arena allows us to maintain cheap, potentially cyclical "references". Mutating only from behind a mutable reference creates patterns that users expect.
Cons: Access to the actual resource requires access to the arena. Functions like
Layout::flatten
would require a reference to the containing library, etc.Replace
Ptr
witharc_swap::ArcSwap
Pros: We're mostly read-heavy so we get to keep our pointer semantics while getting ride of the locks & guards.
Cons: Our individual cells become copy-on-write by necessity.
There are probably other ways of doing this but I think these represent a good start.
My personal inclination would be towards a slotmap/petgraph but I think I would be easily convinced of
ArcSwap
as well.The text was updated successfully, but these errors were encountered: