Skip to content

Commit 69c7480

Browse files
Aaron Hometa-codesync[bot]
authored andcommitted
Upsert instead of remove + insert, improving worst case from timeout to 6min
Summary: When a target's hash or CI labels change, we previously called graph.remove_target() followed by store_target_to_graph(), tearing down all dependency edges and rebuilding them from scratch. This is O(deg) work per update even when the dependency list hasn't changed — which is the common case. This replaces that pattern with upsert_target_in_graph which: 1. Overwrites metadata in-place (store_minimized_target is already idempotent) 2. Diffs regular dep edges: computes old vs new sets, applies only the delta 3. Diffs CI hint edges: same approach for CI hint targets 4. Overwrites CI patterns (store_ci_* methods are already idempotent) For hash-only changes (common case): the edge diff is empty, so zero edge work is done. For dep changes: only the delta edges are touched. For new targets: old edges are empty, so the diff naturally produces only adds. Timeout cases now finish in time: Case 1: Before: >120 min https://www.internalfb.com/sandcastle/workflow/3837066882533555449 After: 6min 16s https://www.internalfb.com/sandcastle/workflow/495395959024731311/insights Case 2: Before: >120 min https://www.internalfb.com/sandcastle/workflow/3837066882533549678 After: 5min 34s https://www.internalfb.com/sandcastle/workflow/198158383618412384 Case 3: Before > 120min https://www.internalfb.com/sandcastle/workflow/3837066882533546745 After: 6min 31s https://www.internalfb.com/sandcastle/workflow/2053641430094751390 BTD succeeds, verse failure is unrelated creds to RiskRunner0 for initial idea Reviewed By: RiskRunner0 Differential Revision: D93272049 fbshipit-source-id: ef814aa6ae416d3d10afa6f1069b9e4e5233bb29
1 parent 08d441d commit 69c7480

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

td_util/src/buck/target_graph.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ macro_rules! impl_string_storage {
6161
macro_rules! impl_collection_storage {
6262
($key_type:ident, $value_type:ident, $store_method:ident, $add_method:ident, $get_method:ident, $len_method:ident, $iter_method:ident, $map_field:ident) => {
6363
pub fn $store_method(&self, key: $key_type, values: Vec<$value_type>) {
64-
if !values.is_empty() {
64+
if values.is_empty() {
65+
self.$map_field.remove(&key);
66+
} else {
6567
self.$map_field.insert(key, values);
6668
}
6769
}
@@ -473,6 +475,10 @@ impl TargetGraph {
473475
self.targets_with_sudo_label.insert(target_id);
474476
}
475477

478+
pub fn unmark_target_has_sudo_label(&self, target_id: TargetId) {
479+
self.targets_with_sudo_label.remove(&target_id);
480+
}
481+
476482
pub fn has_sudo_label(&self, target_id: TargetId) -> bool {
477483
self.targets_with_sudo_label.contains(&target_id)
478484
}

0 commit comments

Comments
 (0)