starknet-rs
starknet-rs copied to clipboard
JSON RPC batching
JSON RPC supports batching multiple requests into one (batching). The performance gain is quite high, for example it takes around 80-100 ms to fetch a single block, but ~200ms to fetch 25 with batching.
Intersting. I didn't know this before. Will implement soon. Thanks!
That would mean we need to make the method calls return some intermedia representation of the requests though, pretty much like we did with Account::execute()
.
Yes, that's the best way to add batching.
Also notice a couple of things:
- The return values can be in any order (the server can process batches in parallel, which is cool), so need to use
id
to reorder them to the caller. Notice that notifications don't produce responses (I don't think starknet rpc uses them so not an issue). - Each individual batch request can fail, so the return value is something like
Vec<Result<Response>>
. - The batch request itself can fail if its malformed.
Thanks for that! I guess a downside of such batching is you'd lose strong typing, unless you only allow batching the same request type.
The library would need a response enum that contains all type of response values. An alternative is to return the raw json values then let users deserialize them (all types support deserialization anyway).
Yeah I mean then you have to do some kind of unwrap. Lemme have a think about how this can be best implemented. Will update this soon :)