-
Notifications
You must be signed in to change notification settings - Fork 417
Give ResponseStore for codeactions a minimum history size of 8 #3194
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
Give ResponseStore for codeactions a minimum history size of 8 #3194
Conversation
Can one of the admins verify this patch? |
Looks reasonable to me unless there's some other reason to reject, @rgrunber ? |
No, I just had a question in the issue itself for Jinbo regarding why it was done this way. My best guess is they assumed that LSP4J would only allow as many parallel requests on a thread pool as parallelism value, but clearly that's not the case. |
Lines 745 to 756 in 161815b
See the specific implementation for But looks into the implementation for // snippets from java.util.concurrent.CompletableFuture
private static final boolean USE_COMMON_POOL =
(ForkJoinPool.getCommonPoolParallelism() > 1);
/**
* Default executor -- ForkJoinPool.commonPool() unless it cannot
* support parallelism.
*/
private static final Executor ASYNC_POOL = USE_COMMON_POOL ?
ForkJoinPool.commonPool() : new ThreadPerTaskExecutor();
public Executor defaultExecutor() {
return ASYNC_POOL;
} |
Using a magic number is acceptable when parallelism fails. However, it’s better to add a comment in the code explaining the reason behind the magic number. This will provide context for future developers in case the magic number causes issues again. |
@ethan-vanderheijden let's adjust the value to |
@rgrunber I think your fundamental assumption is that only the most recent --- Sending request ---
{
id: 5,
method: "textDocument/codeAction",
}
--- Receiving response ---
{
id: 5,
result: [
{
title: "Organize imports"
data: {
pid: 0,
rid: 13
},
...
},
...
],
}
--- Sending request ---
{
id: 6,
method: "textDocument/codeAction",
}
--- Receiving response ---
{
id: 6,
result: [
{
title: "Add Javadoc comment"
data: {
pid: 0,
rid: 14
},
...
},
...
],
}
--- Sending request ---
{
id: 7,
method: "codeAction/resolve",
params: {
data: {
pid: 0,
rid: 13,
},
...
}
} Notice that it is trying to resolve I should clarify how to reproduce this situation:
public class Main {
public static void main(String[] args) throws InterruptedException {
LinkedList<Integer> list = new LinkedList<>();
}
}
It will send the first The issue is that opening Source Actions and moving your cursor will both produce a |
Thanks. I was able to reproduce it. I did have to manually set my code action storage size to
So you're saying we aren't dependent on the number of concurrent threads that the thread pool can support, but rather the number of concurrent requests that might arise from the UI. |
The number of concurrent requests from the UI affects history size, but so does the number of threads. For instance, if we wanted to store the most recent code action response, but 4 requests are processed in parallel, and we don’t know which will be done processing first, then worst case scenario, we need to store the last 4 results. If you want to calculate history size, the following formula should work: # of threads + # of concurrent UI requests - 1 However, if “# of threads” is 1, then it switches to All of this is over-engineered. I suggest hardcoding history size to a large number like 32. Are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, then I'm fine with what you currently have, which is Math.max(ForkJoinPool.commonPool().getParallelism(), 8)
. I can't see a case where the UI would result in more than 8 parallel code action requests. I would just add a comment explaining what the 2 variables are that affect the total number of parallel code action requests.
I'd also just change the commit message to :
Give ResponseStore for code actions a minimum history size of 8.
6a9fe1d
to
88c65ce
Compare
88c65ce
to
e093f55
Compare
Fixes #3180
I'm not entirely clear on why history size is tied to processor count. Is it because a client with more processors tends to issue more
textDocument/codeAction
requests? Either way, setting a minimum history size shouldn't cause any problems. Selecting an item from the source action menu tends to issue 2-4 requests, so I chose 8 as a safe minimum size.