summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-11-30 16:43:35 +0100
committerGitHub <noreply@github.com>2023-11-30 15:43:35 +0000
commitc803c0eaab2b61c77fd187fc5c6f3898c29e8fc4 (patch)
treecbf1bc398ce1425bc6a4cd7e2b88d3e525513a2b
parent3591ba8578b5eff96c13afc6fdfcf95a96083761 (diff)
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.
-rw-r--r--cli/tsc/99_main_compiler.js21
1 files changed, 4 insertions, 17 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index 4c750cfe7..1b2e70dd6 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -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,