Skip to content

Conversation

@JDevlieghere
Copy link
Member

Reading a source file might take a while, for example because it's located on a virtual file system that's fetching the data on demand. This PR emits a progress event to convey this to the user when reading the file exceeds a certain threshold (250ms). Although it doesn't speed up the operation, it still greatly improves the user experience by helping them understand what's going on.

rdar://163750392

Reading a source file might take a while, for example because it's
located on a virtual file system that's fetching the data on demand.
This PR emits a progress event to convey this to the user when reading
the file exceeds a certain threshold (250ms). Although it doesn't speed
up the operation, it still greatly improves the user experience by
helping them understand what's going on.

rdar://163750392
@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Reading a source file might take a while, for example because it's located on a virtual file system that's fetching the data on demand. This PR emits a progress event to convey this to the user when reading the file exceeds a certain threshold (250ms). Although it doesn't speed up the operation, it still greatly improves the user experience by helping them understand what's going on.

rdar://163750392


Full diff: https://github.com/llvm/llvm-project/pull/165802.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Core/SourceManager.h (+2)
  • (modified) lldb/source/Core/SourceManager.cpp (+24-2)
diff --git a/lldb/include/lldb/Core/SourceManager.h b/lldb/include/lldb/Core/SourceManager.h
index 1244291596b73..83dc74768733d 100644
--- a/lldb/include/lldb/Core/SourceManager.h
+++ b/lldb/include/lldb/Core/SourceManager.h
@@ -109,6 +109,8 @@ class SourceManager {
   private:
     void CommonInitializer(lldb::SupportFileSP support_file_sp,
                            lldb::TargetSP target_sp);
+    void CommonInitializerImpl(lldb::SupportFileSP support_file_sp,
+                               lldb::TargetSP target_sp);
   };
 
   typedef std::shared_ptr<File> FileSP;
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index f786866a18137..9ad483d8a9232 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -34,6 +34,7 @@
 
 #include "llvm/ADT/Twine.h"
 
+#include <future>
 #include <memory>
 #include <optional>
 #include <utility>
@@ -54,8 +55,7 @@ using namespace lldb_private;
 static inline bool is_newline_char(char ch) { return ch == '\n' || ch == '\r'; }
 
 static void resolve_tilde(FileSpec &file_spec) {
-  if (!FileSystem::Instance().Exists(file_spec) &&
-      file_spec.GetDirectory() &&
+  if (!FileSystem::Instance().Exists(file_spec) && file_spec.GetDirectory() &&
       file_spec.GetDirectory().GetCString()[0] == '~') {
     FileSystem::Instance().Resolve(file_spec);
   }
@@ -477,6 +477,28 @@ SourceManager::File::File(SupportFileSP support_file_sp, TargetSP target_sp)
 
 void SourceManager::File::CommonInitializer(SupportFileSP support_file_sp,
                                             TargetSP target_sp) {
+  // It might take a while to read a source file, for example because it's
+  // coming from a virtual file system that's fetching the data on demand. When
+  // reading the data exceeds a certain threshold, show a progress event to let
+  // the user know what's going on.
+  static constexpr auto g_progress_delay = std::chrono::milliseconds(500);
+
+  std::future<void> future = std::async(std::launch::async, [&]() {
+    CommonInitializer(support_file_sp, target_sp);
+  });
+
+  std::optional<Progress> progress;
+  if (future.wait_for(g_progress_delay) == std::future_status::timeout) {
+    Debugger *debugger = target_sp ? &target_sp->GetDebugger() : nullptr;
+    progress.emplace("Loading source file",
+                     support_file_sp->GetSpecOnly().GetFilename().GetString(),
+                     1, debugger);
+  }
+  future.wait();
+}
+
+void SourceManager::File::CommonInitializerImpl(SupportFileSP support_file_sp,
+                                                TargetSP target_sp) {
   // Set the file and update the modification time.
   SetSupportFile(support_file_sp);
 

Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

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

Nice

@JDevlieghere JDevlieghere requested a review from Copilot October 31, 2025 15:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a progress indicator mechanism for loading source files in the LLDB source manager. The implementation spawns an async task to perform the actual file loading and displays a progress event if the operation takes longer than 500ms.

  • Adds async loading with progress reporting for source files
  • Splits CommonInitializer into wrapper and implementation functions
  • Reformats a long conditional expression in resolve_tilde

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lldb/source/Core/SourceManager.cpp Adds async task and progress reporting logic to CommonInitializer, creates CommonInitializerImpl for actual initialization, reformats resolve_tilde conditional
lldb/include/lldb/Core/SourceManager.h Declares new CommonInitializerImpl private method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JDevlieghere JDevlieghere merged commit 22d2f7f into llvm:main Oct 31, 2025
8 of 9 checks passed
@JDevlieghere JDevlieghere deleted the source-manager-progress branch October 31, 2025 20:10
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Oct 31, 2025
Reading a source file might take a while, for example because it's
located on a virtual file system that's fetching the data on demand.

This PR emits a progress event to convey this to the user when reading
the file exceeds a certain threshold (500ms). Although it doesn't speed
up the operation, it still greatly improves the user experience by
helping them understand what's going on.

rdar://163750392
(cherry picked from commit 22d2f7f)
DEBADRIBASAK pushed a commit to DEBADRIBASAK/llvm-project that referenced this pull request Nov 3, 2025
Reading a source file might take a while, for example because it's
located on a virtual file system that's fetching the data on demand.

This PR emits a progress event to convey this to the user when reading
the file exceeds a certain threshold (500ms). Although it doesn't speed
up the operation, it still greatly improves the user experience by
helping them understand what's going on.

rdar://163750392
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Nov 4, 2025
[lldb] Emit a progress event from the source manager (llvm#165802)

Reading a source file might take a while, for example because it's located on a virtual file system that's fetching the data on demand.

This PR emits a progress event to convey this to the user when reading the file exceeds a certain threshold (500ms). Although it doesn't speed up the operation, it still greatly improves the user experience by helping them understand what's going on.

rdar://163750392
(cherry picked from commit 22d2f7f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants