0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00

perf(lsp): remove throttling of cancellation token (#21395)

This commit removes "ThrottledCancellationToken" in favor of
"CancellationToken".

Since calling into Rust to check if Tokio's cancellation token has
already been canceled is really cheap, there's no need for us to 
throttle this check and let TSC burn up CPU with heavy computation.
This commit is contained in:
Bartek Iwańczuk 2023-11-30 16:43:35 +01:00
parent 58101fa904
commit 98a6c21821
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750

View file

@ -485,26 +485,13 @@ delete Object.prototype.__proto__;
class OperationCanceledError extends Error {
}
// todo(dsherret): we should investigate if throttling is really necessary
/**
* Inspired by ThrottledCancellationToken in ts server.
*
* We don't want to continually call back into Rust and so
* we throttle cancellation checks to only occur once
* in a while.
* This implementation calls into Rust to check if Tokio's cancellation token
* has already been canceled.
* @implements {ts.CancellationToken}
*/
class ThrottledCancellationToken {
#lastCheckTimeMs = 0;
class CancellationToken {
isCancellationRequested() {
const timeMs = Date.now();
// TypeScript uses 20ms
if ((timeMs - this.#lastCheckTimeMs) < 20) {
return false;
}
this.#lastCheckTimeMs = timeMs;
return ops.op_is_cancelled();
}
@ -542,7 +529,7 @@ delete Object.prototype.__proto__;
},
getCancellationToken() {
// createLanguageService will call this immediately and cache it
return new ThrottledCancellationToken();
return new CancellationToken();
},
getSourceFile(
specifier,