From 5b1cff33886090b018ef16ed3abc509601e838da Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 3 Apr 2025 17:35:40 +0200 Subject: just: Interleave graph dumping with other tasks ... and only as late as possible wait for that parallel task. Serializing a large task to JSON can take several seconds and as building does not depend on it, we shouldn't delay the build for with extra information. --- src/buildtool/main/main.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 108b9798..158b4a9b 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -1182,26 +1183,31 @@ auto main(int argc, char* argv[]) -> int { not_eligible); } - analyse_result->result_map.ToFile( - arguments.analysis.graph_file, &stats, &progress); - analyse_result->result_map.ToFile( - arguments.analysis.graph_file_plain, &stats, &progress); - auto const [artifacts, runfiles] = + auto const artifacts_runfiles = ReadOutputArtifacts(analyse_result->target); - if (arguments.analysis.artifacts_to_build_file) { - DumpArtifactsToBuild( - artifacts, - runfiles, - *arguments.analysis.artifacts_to_build_file); - } - if (arguments.cmd == SubCommand::kAnalyse) { - DiagnoseResults(*analyse_result, arguments.diagnose); - ReportTaintedness(*analyse_result); + + auto const& [artifacts, runfiles] = artifacts_runfiles; + auto dump_and_cleanup = [&]() { + analyse_result->result_map.ToFile( + arguments.analysis.graph_file, &stats, &progress); + analyse_result->result_map.ToFile( + arguments.analysis.graph_file_plain, &stats, &progress); + if (arguments.analysis.artifacts_to_build_file) { + DumpArtifactsToBuild( + artifacts_runfiles.first, + artifacts_runfiles.second, + *arguments.analysis.artifacts_to_build_file); + } // Clean up in parallel { TaskSystem ts{arguments.common.jobs}; analyse_result->result_map.Clear(&ts); } + }; + if (arguments.cmd == SubCommand::kAnalyse) { + DiagnoseResults(*analyse_result, arguments.diagnose); + dump_and_cleanup(); + ReportTaintedness(*analyse_result); if (profile) { (*profile)->Write(kExitSuccess); } @@ -1217,11 +1223,7 @@ auto main(int argc, char* argv[]) -> int { analyse_result->result_map.CacheTargets(); auto cache_artifacts = CollectNonKnownArtifacts(cache_targets); - // Clean up analyse_result map, now that it is no longer needed - { - TaskSystem ts{arguments.common.jobs}; - analyse_result->result_map.Clear(&ts); - } + std::thread dump_and_cleanup_thread(dump_and_cleanup); Logger::Log( LogLevel::Info, @@ -1241,6 +1243,7 @@ auto main(int argc, char* argv[]) -> int { std::move(blobs), std::move(trees), std::move(cache_artifacts)); + dump_and_cleanup_thread.join(); if (build_result) { WriteTargetCacheEntries( cache_targets, -- cgit v1.2.3