Skip to content

Commit 3c4929e

Browse files
tyao1meta-codesync[bot]
authored andcommitted
S3: Prefetch Eden hash map
Reviewed By: shashkambham Differential Revision: D94758834 fbshipit-source-id: 337a612a45b8e9c74432364d79730a57daa49449
1 parent d8fb34c commit 3c4929e

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

compiler/crates/relay-compiler/src/build_project.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use graphql_ir::FragmentDefinitionNameSet;
5858
use graphql_ir::Program;
5959
use indexmap::IndexSet;
6060
use log::debug;
61+
use log::error;
6162
use log::info;
6263
use log::warn;
6364
use petgraph::unionfind::UnionFind;
@@ -595,6 +596,19 @@ pub async fn commit_project(
595596
return Err(BuildProjectFailure::Cancelled);
596597
}
597598

599+
// Start hash map prefetch as a background task. The closure extracts
600+
// artifact paths synchronously, then the spawned future does the async
601+
// Eden Thrift RPC (~5-10s). This overlaps the network I/O with
602+
// persist_operations and generate_extra_artifacts below.
603+
let hash_map_handle = if !artifacts.is_empty() {
604+
config
605+
.get_artifacts_file_hash_map
606+
.as_ref()
607+
.map(|get_fn| tokio::spawn(get_fn(&artifacts)))
608+
} else {
609+
None
610+
};
611+
598612
if let Some(operation_persister) = config
599613
.create_operation_persister
600614
.as_ref()
@@ -649,19 +663,21 @@ pub async fn commit_project(
649663
}
650664
};
651665

652-
let artifacts_file_hash_map = if artifacts.is_empty() {
653-
None
654-
} else {
655-
match &config.get_artifacts_file_hash_map {
656-
Some(get_fn) => {
657-
let get_artifacts_file_hash_map_timer =
658-
log_event.start("get_artifacts_file_hash_map_time");
659-
let res = get_fn(&artifacts).await;
660-
log_event.stop(get_artifacts_file_hash_map_timer);
661-
res
662-
}
663-
_ => None,
666+
// Await the prefetched hash map. The timer measures only the remaining
667+
// wait time — if the Eden RPC completed during persist/generate above,
668+
// this resolves immediately (~0ms).
669+
let artifacts_file_hash_map = match hash_map_handle {
670+
Some(handle) => {
671+
let get_artifacts_file_hash_map_timer =
672+
log_event.start("get_artifacts_file_hash_map_time");
673+
let res = handle.await.unwrap_or_else(|e| {
674+
error!("hash map prefetch failed: {e}");
675+
None
676+
});
677+
log_event.stop(get_artifacts_file_hash_map_timer);
678+
res
664679
}
680+
None => None,
665681
};
666682

667683
// Write the generated artifacts to disk. This step is separate from

compiler/crates/relay-compiler/src/build_project/get_artifacts_file_hash_map.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ use rustc_hash::FxHashMap;
1010

1111
use super::Artifact;
1212

13+
/// Function that fetches existing file hashes for artifacts from a fast source
14+
/// (e.g. Eden's Thrift API) to avoid unnecessary writes.
15+
///
16+
/// The returned future must be `'static` (not borrow the input slice) so it can
17+
/// be spawned as a background task and overlapped with other commit work.
18+
/// Implementations should extract any needed data (e.g. file paths) from the
19+
/// artifact slice synchronously before returning the async future.
1320
pub type GetArtifactsFileHashMapFn = Box<
1421
dyn Send
1522
+ Sync
16-
+ for<'a> Fn(&'a [Artifact]) -> BoxFuture<'a, Option<FxHashMap<String, Option<String>>>>,
23+
+ Fn(&[Artifact]) -> BoxFuture<'static, Option<FxHashMap<String, Option<String>>>>,
1724
>;

0 commit comments

Comments
 (0)