Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(txpool|p2p): use seqlock instead of small copy-able RwLocks #2524
feat(txpool|p2p): use seqlock instead of small copy-able RwLocks #2524
Changes from 4 commits
8b5efe5
ecf703c
6fc3ae6
b1d7649
484c844
118c37a
cba91d8
9b0fe75
720d486
5db45fe
883c27b
a99a96d
a51c60c
6d626b5
72e09f9
6f30b26
51d079c
28becc9
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a trait for this
T
to guarantee that it's below 64 bytes and provide some default impls for the types we expect to see.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(chiming in) perhaps
Small
should implyCopy
in this case:pub trait Small: Copy;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't quite like the idea of creating default impls here ~ we won't be able to implement the trait for types outside the crate either due to the orphan rule.
I can enforce the type size at runtime if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if two writers try to update the value concurrently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well they shouldn't
this is designed for single writer only
there's a lot of foot guns with this implementation, and makes it highly specific for one use case -
I can add as a warning comment if you'd like
I want to avoid write locks because this assumes only a single writer exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmk if this comment works: 118c37a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, the comment looks good :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we guarantee that only a single writer exists? Like, on construction we just generate a
SeqLockWriter
and from that we can generate any number ofSeqLockReader
s, but it'sSeqLockWriter
isn't cloneable?Essentially like a single producer, multiple consumer channel.
Internally, it's the same, but we expose different
mut
apis for theSeqLockWriter
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 720d486
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably call
std::thread::yield_now
beforecontinue
. See https://github.com/Amanieu/seqlock/blob/b72653fd9c38141da7e588a97a1b654239f5d4df/src/lib.rs#L126There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 51d079c