Skip to content

[sourcekitd] Be more aggresive with the semantic editor delay to avoid being throttled #13147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tools/SourceKit/tools/sourcekitd/bin/XPC/Client/sourcekitd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ static void updateSemanticEditorDelay() {
using namespace std::chrono;
using TimePoint = time_point<system_clock, nanoseconds>;

// This minimum is chosen to keep us from being throttled by XPC.
static const size_t MinDelaySeconds = 10;
static const size_t MaxDelaySeconds = 20;

// Clear any previous setting.
SemanticEditorDelaySecondsNum = 0;

Expand All @@ -417,16 +421,13 @@ static void updateSemanticEditorDelay() {
TimePoint PrevTime = gPrevCrashTime;
TimePoint CurrTime = system_clock::now();
gPrevCrashTime = CurrTime;
if (PrevTime == TimePoint()) {
// First time that it crashed.
return;
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ handleSemanticRequest(RequestDict Req,

llvm::SmallString<64> ErrBuf;

if (isSemanticEditorDisabled())
return Rec(createErrorRequestFailed("semantic editor is disabled"));

if (ReqUID == RequestCodeComplete) {
std::unique_ptr<llvm::MemoryBuffer>
InputBuf = getInputBufForRequest(SourceFile, SourceText, ErrBuf);
Expand Down Expand Up @@ -767,9 +770,6 @@ handleSemanticRequest(RequestDict Req,
return Rec(indexSource(*SourceFile, Args, Hash));
}

if (isSemanticEditorDisabled())
return Rec(createErrorRequestFailed("semantic editor is disabled"));

if (ReqUID == RequestCursorInfo) {
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();

Expand Down