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(anvil): add ipc support #3134
Conversation
async fn on_request(&self, request: Self::Request, cx: PubSubContext<Self>) -> ResponseResult; | ||
} | ||
|
||
type Subscriptions<SubscriptionId, Subscription> = Arc<Mutex<Vec<(SubscriptionId, Subscription)>>>; |
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.
Why a vec and not a map of subid to subscriptions?
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.
this is a vec so we can easily poll them one in round robinish fashion
polling also requires pinning which is easier when you have mut self
and are not constrained by working with a &mut ref of a map
foundry/anvil/server/src/ws.rs
Lines 257 to 259 in e7a4e3b
let mut subscriptions = pin.context.subscriptions.lock(); | |
'outer: for n in (0..subscriptions.len()).rev() { | |
let (id, mut sub) = subscriptions.swap_remove(n); |
lookup is only done when adding/removing subscriptions so the overhead is quite small
} | ||
} | ||
|
||
struct JsonRpcCodec; |
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.
Are we OK with writing our own codecs? Is this something we should start refactoring, eg for have in reth?
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.
the current state of the different codec traits and AsyncReadWrite + Stream/Sink is a bit of a mess...
we probably only need this when we something that's only AsyncWrite/AsyncRead but we need a stream,
The way this currently works is Framed::new(asyncread+asyncwrite, codec)
the codec here determines when a new framed
object can be produced as Stream::Item
this codec basically finds enclosed json objects via {
and determines when a full object is in the buffer and can be deserialized.
sweet! thanks for this feature. I measured circa 40% performance boost when using ipc over websockets. (using web3py) |
* refactor: rename pubusb * feat: add ipc support * feat: impl IpcConn * docs * feat: integrate ipc service * fix: use futures ready * feat: more ipc impls * fix: always flush * typos instrument
Motivation
Closes #2023
Solution
WsConnection
->PubSubConnection
and abstract overConnection
so it can be used by anything that's Stream+Sink