Skip to content

Commit 692dd86

Browse files
committed
[sourcekitd] Be more aggresive with the semantic editor delay
Set a minimum delay of 10 seconds for the semantic editor instead of starting from 0/1 second. This helps prevent us from being throttled by the system if we have multiple crashes in a row, which allows us to keep syntactic requests working. rdar://18326221
1 parent de7a517 commit 692dd86

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tools/SourceKit/tools/sourcekitd/bin/XPC/Client/sourcekitd.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ static void updateSemanticEditorDelay() {
409409
using namespace std::chrono;
410410
using TimePoint = time_point<system_clock, nanoseconds>;
411411

412+
// This minimum is chosen to keep us from being throttled by XPC.
413+
static const size_t MinDelaySeconds = 10;
414+
static const size_t MaxDelaySeconds = 20;
415+
412416
// Clear any previous setting.
413417
SemanticEditorDelaySecondsNum = 0;
414418

@@ -417,16 +421,13 @@ static void updateSemanticEditorDelay() {
417421
TimePoint PrevTime = gPrevCrashTime;
418422
TimePoint CurrTime = system_clock::now();
419423
gPrevCrashTime = CurrTime;
420-
if (PrevTime == TimePoint()) {
421-
// First time that it crashed.
422-
return;
423-
}
424424

425425
auto Diff = duration_cast<seconds>(CurrTime - PrevTime);
426+
size_t Delay = Diff.count()*2 + 1;
426427
if (Diff.count() > 30)
427-
return; // treat this as more likely unrelated to the previous crash.
428+
Delay = 0; // Treat this as more likely unrelated to the previous crash.
429+
Delay = std::min(std::max(Delay, MinDelaySeconds), MaxDelaySeconds);
428430

429-
size_t Delay = std::min(size_t(20), size_t(Diff.count()*2 + 1));
430431
LOG_WARN_FUNC("disabling semantic editor for " << Delay << " seconds");
431432
SemanticEditorDelaySecondsNum = Delay;
432433

0 commit comments

Comments
 (0)