-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Our software design for IPA require protocol contexts to be cheaply cloneable because we clone them a lot.
pub struct SemiHonestContext<'a, F: Field> {
inner: Arc<ContextInner<'a>>,
step: Step,
}
Making steps cloning inexpensive is tracked in #139, this issue focuses on improvements that can be made on protocol contexts, specifically on ContextInner
clone. It looks innocent (atomic load/store on each clone) but when doing it often it may lead to false sharing issues on CPU caches. There may be a better way to do this if we look at the structure of the ContextInner
struct:
pub(super) struct ContextInner<'a> {
pub role: Role,
pub prss: &'a PrssEndpoint,
pub gateway: &'a Gateway,
}
There is a role bit and two references that never change no matter how many times we clone the context. There might be an opportunity to cache those values (not references) in one place. Root-level future that is created to run protocol may be a good place to do that and Tokio crate provides some support for it: https://docs.rs/tokio/latest/tokio/task/struct.LocalKey.html.
10000 foot view
This is how query processing may look like
- Helpers receive a request to process new query. They dynamically allocate roles for each of them and set up PRSS.
- Each helper stores role, PRSS endpoint and Gateway inside task local data cell (tokio localkey)
- Query processing is launched by spawning a tokio task (or any other runtime task). In case of tokio it would look like
tokio::spawn(|| async {
CONTEXT_INNER.scope((prss, gateway, role), async move {
let context = SemiHonestContext::new("step"); // no need to pass PRSS or Gateway anymore
}).await;
});
impl SemiHonestContext {
pub fn prss(&self) -> &PrssEndpoint {
CONTEXT_INNER.with(|inner| inner.0) // not sure if that works fine
}
}
This design does not require changing protocols code, everything is contained within Infra layer
Complications
- Our plan is to run IPA software on Cloudflare Workers that do not support Tokio: https://github.com/cloudflare/workers-rs.
LocalKey
implementation however does not depend on tokio runtime so there may be no issues - This change will require changes in our test infrastructure. Every test needs to set up per-task data before running any computation.
TestWorld::contexts()
function usage becomes problematic, but luckily most of our tests useRunner
interface that can easily hide that compexity inside.