Skip to content
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

Only run one completion sampler #7897

Merged
merged 1 commit into from
Oct 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ public void indexingComplete(Set<URL> indexedRoots) {
private static final int INITIAL_COMPLETION_SAMPLING_DELAY = 1000;
private static final int DEFAULT_COMPLETION_WARNING_LENGTH = 10_000;
private static final RequestProcessor COMPLETION_SAMPLER_WORKER = new RequestProcessor("java-lsp-completion-sampler", 1, false, false);
private static final AtomicReference<Sampler> RUNNING_SAMPLER = new AtomicReference<>();

@Override
@Messages({
Expand All @@ -366,11 +367,15 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
if (!done.get()) {
Sampler sampler = Sampler.createSampler("completion");
if (sampler != null) {
sampler.start();
samplerRef.set(sampler);
samplingStart.set(System.currentTimeMillis());
if (done.get()) {
sampler.stop();
Sampler witnessSampler = RUNNING_SAMPLER.compareAndExchange(null, sampler);

if (witnessSampler == null) {
sampler.start();
samplerRef.set(sampler);
samplingStart.set(System.currentTimeMillis());
if (done.get()) {
sampler.stop();
}
}
}
}
Expand Down Expand Up @@ -494,6 +499,7 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio

done.set(true);
Sampler sampler = samplerRef.get();
RUNNING_SAMPLER.compareAndExchange(sampler, null);
if (sampler != null) {
long samplingTime = (System.currentTimeMillis() - completionStart);
long minSamplingTime = Math.min(1_000, samplingWarningLength.get());
Expand Down
Loading