From 3334e9e8ae0324565b46df0dbce914d8e900b71d Mon Sep 17 00:00:00 2001 From: Andrea Campi Date: Tue, 10 Dec 2024 08:12:06 -0800 Subject: [PATCH] Optimize commit_file_diffs by running xdiff::diff_unified in a different thread Summary: ## This stack Track and down methods that are holding up the reactor and optimize them. ## This diff `xdiff::diff_unified` is synchronous and does a lot of work to format a diff. While we should optimize it, it is older code so that will realistically take a while. Running it on a separate, non-executor thread gets the job done. Reviewed By: lmvasquezg Differential Revision: D67025628 fbshipit-source-id: 1f946e8f7aabc0eb8f632a5724ed3a608ec6d877 --- eden/mononoke/mononoke_api/src/changeset_path_diff.rs | 4 +++- eden/mononoke/mononoke_api/src/errors.rs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/eden/mononoke/mononoke_api/src/changeset_path_diff.rs b/eden/mononoke/mononoke_api/src/changeset_path_diff.rs index 5562ed25b0f36..132f5d06fae93 100644 --- a/eden/mononoke/mononoke_api/src/changeset_path_diff.rs +++ b/eden/mononoke/mononoke_api/src/changeset_path_diff.rs @@ -530,7 +530,9 @@ impl ChangesetPathDiffContext { copy_info, }; // The base is the target, so we diff in the opposite direction. - let raw_diff = xdiff::diff_unified(other_file, base_file, opts); + let raw_diff = + tokio::task::spawn_blocking(move || xdiff::diff_unified(other_file, base_file, opts)) + .await?; Ok(UnifiedDiff { raw_diff, is_binary, diff --git a/eden/mononoke/mononoke_api/src/errors.rs b/eden/mononoke/mononoke_api/src/errors.rs index f45c444c4f6d6..17b6091dcda96 100644 --- a/eden/mononoke/mononoke_api/src/errors.rs +++ b/eden/mononoke/mononoke_api/src/errors.rs @@ -28,6 +28,7 @@ use mononoke_types::ChangesetId; use pushrebase::PushrebaseError; use repo_authorization::AuthorizationError; use thiserror::Error; +use tokio::task::JoinError; #[derive(Clone, Debug)] pub struct InternalError(Arc); @@ -213,3 +214,9 @@ impl From for MononokeError { } } } + +impl From for MononokeError { + fn from(e: JoinError) -> Self { + MononokeError::from(anyhow::Error::from(e)) + } +}