-
Notifications
You must be signed in to change notification settings - Fork 25
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
Support background analysis #13
Comments
I am having a performance issue with pyright on a particular file that has a long analysis time (over 4 secs), which can freeze emacs. By this I mean that I can type characters and they actually don't appear on the screen until the analysis is completed. Sounds like having analysis cancellation may solve this issue for me. |
This is interesting, if I am seeing
|
@dam5h Can you check the performance difference with VSCode pyright/pylance?
I think not supported yet, @seagle0128 any specific reasons for closing? |
@zeronone , I don't actually have VS Code installed, but I had an exchange with on Gitter with @msfterictraut (main https://gitter.im/microsoft-pyright/community?at=5f95abac7be0d67d279778e1 |
@zeronone sorry, closed it by mistake somehow. Reopen it now. |
Looks like case Commands.createTypeStub: {
return this._createStub.execute(cmdParams, token);
} So seems with a async execute(cmdParams: ExecuteCommandParams, token: CancellationToken): Promise<any> {
if (cmdParams.arguments && cmdParams.arguments.length >= 2) {
const service = await this._createTypeStubService(callingFile); |
Just to share my findings, if I understood it correctly, VSCode by default sends an additional argument to pyright that enables some sort of file-based background job cancellation strategy (probably when the file is changed, it cancels the jobs for that file). one, two In our case we don't send any such argument, so the However looking at the code, it seems to also support message-based cancellation strategy, however it can't be used due to the additional check in |
I think option 1 is the simple and reasonable method. Do you know how to send the addtional arg in elisp? |
Message-based cancellation won't work because this language server is written in TypeScript (javascript) and doesn't run on a separate thread from message handling. If you send a cancellation via message, the message won't be received or processed until after the operation is complete. A file-based cancellation mechanism works because changes can be polled from the inner loop of a long analysis operation. |
@erictraut Thanks a lot for your input, and the great tool. I guess then we can't go with the message-based strategy. Can you point to the documentation for the file-based cancellation strategy? I couldn't find any :( I assume we should create a directory where each file acts as token for a background job; and if the file is deleted the background job is also cancelled. Is it correct? If correct, I am wondering when the files should be created/deleted and what are the contents of the files. @seagle0128 Sending the additional argument should be easy, but we also need to support the cancellation strategy. I don't know if lsp-mode has such feature yet. |
So we have two things going on here
for cancellation, the pyright process needs another argument as discussed. and vscode extension code is here. Maybe need to mimic the behavior as
cancellationStrategy = new FileBasedCancellationStrategy();
export class FileBasedCancellationStrategy implements CancellationStrategy, Disposable {
constructor() {
const folderName = randomBytes(21).toString('hex');
this._sender = new FileCancellationSenderStrategy(folderName);
}
getCommandLineArguments(): string[] {
return [`--cancellationReceive=file:${this._sender.folderName}`];
} and this sender sends cancellation by simply writing empty string to this file with name from class FileCancellationSenderStrategy implements CancellationSenderStrategy {
sendCancellation(_: MessageConnection, id: CancellationId): void {
const file = getCancellationFilePath(this.folderName, id);
tryRun(() => fs.writeFileSync(file, '', { flag: 'w' }));
} |
+1 this feature would be very useful addition to lsp-pyright. As of now, in my MBP the CPU usage is very high with this, and lsp-log shows |
ping for this feature, I keep having this problem so much that I can't use it.
|
|
I'm getting this a lot - 4s for the long analysis operations. Did anyone find a workaround for this, or did anyone manage to get an implementation for the file based cancellation? |
I think it should be reported to upstream. |
Pyright
VSCode extension, however it is not enabled for us.pyright-langserver
(https://github.com/microsoft/pyright/blob/master/server/src/server.ts#L151)The text was updated successfully, but these errors were encountered: