Skip to content

Commit

Permalink
chore: remove unnecessary boxing (#2191)
Browse files Browse the repository at this point in the history
Co-authored-by: Amit Singh <amitksingh1490@gmail.com>
  • Loading branch information
meskill and amitksingh1490 committed Jun 15, 2024
1 parent ab0b519 commit 7f57834
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
21 changes: 10 additions & 11 deletions src/core/data_loader/dedupe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;
use std::hash::Hash;
use std::pin::Pin;
use std::sync::{Arc, Mutex};

use futures_util::Future;
Expand Down Expand Up @@ -34,11 +33,11 @@ impl<K: Key, V: Value> Dedupe<K, V> {
Self { cache: Arc::new(Mutex::new(HashMap::new())), size, persist }
}

pub async fn dedupe<'a>(
&'a self,
key: &'a K,
or_else: impl FnOnce() -> Pin<Box<dyn Future<Output = V> + 'a + Send>> + Send,
) -> V {
pub async fn dedupe<'a, Fn, Fut>(&'a self, key: &'a K, or_else: Fn) -> V
where
Fn: FnOnce() -> Fut,
Fut: Future<Output = V>,
{
match self.step(key) {
Step::Value(value) => value,
Step::Recv(mut rx) => rx.recv().await.unwrap(),
Expand Down Expand Up @@ -81,11 +80,11 @@ impl<K: Key, V: Value, E: Value> DedupeResult<K, V, E> {
}

impl<K: Key, V: Value, E: Value> DedupeResult<K, V, E> {
pub async fn dedupe<'a>(
&'a self,
key: &'a K,
or_else: impl FnOnce() -> Pin<Box<dyn Future<Output = Result<V, E>> + 'a + Send>> + Send,
) -> Result<V, E> {
pub async fn dedupe<'a, Fn, Fut>(&'a self, key: &'a K, or_else: Fn) -> Result<V, E>
where
Fn: FnOnce() -> Fut,
Fut: Future<Output = Result<V, E>>,
{
self.0.dedupe(key, or_else).await
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/core/ir/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ impl Eval for IO {
Box::pin(async move {
ctx.request_ctx
.cache
.dedupe(&key, || {
Box::pin(async {
ctx.request_ctx
.dedupe_handler
.dedupe(&key, || Box::pin(self.eval_inner(ctx)))
.await
})
.dedupe(&key, || async {
ctx.request_ctx
.dedupe_handler
.dedupe(&key, || self.eval_inner(ctx))
.await
})
.await
})
Expand Down

1 comment on commit 7f57834

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.64ms 3.05ms 79.11ms 72.24%
Req/Sec 3.81k 190.21 4.35k 91.92%

454905 requests in 30.02s, 2.28GB read

Requests/sec: 15153.37

Transfer/sec: 77.78MB

Please sign in to comment.