Skip to content

Commit 0ee51b9

Browse files
authored
More baselining for timeouts that make furture changes easier (microsoft#53579)
1 parent 5586727 commit 0ee51b9

File tree

594 files changed

+6957
-2345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

594 files changed

+6957
-2345
lines changed

src/compiler/sys.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function createDynamicPriorityPollingWatchFile(host: {
286286
return queue;
287287
}
288288

289-
function pollPollingIntervalQueue(queue: PollingIntervalQueue) {
289+
function pollPollingIntervalQueue(_timeoutType: string, queue: PollingIntervalQueue) {
290290
queue.pollIndex = pollQueue(queue, queue.pollingInterval, queue.pollIndex, pollingChunkSize[queue.pollingInterval]);
291291
// Set the next polling index and timeout
292292
if (queue.length) {
@@ -298,12 +298,12 @@ function createDynamicPriorityPollingWatchFile(host: {
298298
}
299299
}
300300

301-
function pollLowPollingIntervalQueue(queue: PollingIntervalQueue) {
301+
function pollLowPollingIntervalQueue(_timeoutType: string, queue: PollingIntervalQueue) {
302302
// Always poll complete list of changedFilesInLastPoll
303303
pollQueue(changedFilesInLastPoll, PollingInterval.Low, /*pollIndex*/ 0, changedFilesInLastPoll.length);
304304

305305
// Finally do the actual polling of the queue
306-
pollPollingIntervalQueue(queue);
306+
pollPollingIntervalQueue(_timeoutType, queue);
307307
// Schedule poll if there are files in changedFilesInLastPoll but no files in the actual queue
308308
// as pollPollingIntervalQueue wont schedule for next poll
309309
if (!queue.pollScheduled && changedFilesInLastPoll.length) {
@@ -374,7 +374,7 @@ function createDynamicPriorityPollingWatchFile(host: {
374374
}
375375

376376
function scheduleNextPoll(pollingInterval: PollingInterval) {
377-
pollingIntervalQueue(pollingInterval).pollScheduled = host.setTimeout(pollingInterval === PollingInterval.Low ? pollLowPollingIntervalQueue : pollPollingIntervalQueue, pollingInterval, pollingIntervalQueue(pollingInterval));
377+
pollingIntervalQueue(pollingInterval).pollScheduled = host.setTimeout(pollingInterval === PollingInterval.Low ? pollLowPollingIntervalQueue : pollPollingIntervalQueue, pollingInterval, pollingInterval === PollingInterval.Low ? "pollLowPollingIntervalQueue" : "pollPollingIntervalQueue", pollingIntervalQueue(pollingInterval));
378378
}
379379
}
380380

@@ -465,7 +465,7 @@ function createFixedChunkSizePollingWatchFile(host: {
465465

466466
function scheduleNextPoll() {
467467
if (!watchedFiles.length || pollScheduled) return;
468-
pollScheduled = host.setTimeout(pollQueue, PollingInterval.High);
468+
pollScheduled = host.setTimeout(pollQueue, PollingInterval.High, "pollQueue");
469469
}
470470
}
471471

@@ -713,7 +713,7 @@ function createDirectoryWatcherSupportingRecursive({
713713
clearTimeout(timerToUpdateChildWatches);
714714
timerToUpdateChildWatches = undefined;
715715
}
716-
timerToUpdateChildWatches = setTimeout(onTimerToUpdateChildWatches, 1000);
716+
timerToUpdateChildWatches = setTimeout(onTimerToUpdateChildWatches, 1000, "timerToUpdateChildWatches");
717717
}
718718

719719
function onTimerToUpdateChildWatches() {

src/compiler/tsbuildPublic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,10 +2258,10 @@ function scheduleBuildInvalidatedProject<T extends BuilderProgram>(state: Soluti
22582258
if (state.timerToBuildInvalidatedProject) {
22592259
hostWithWatch.clearTimeout(state.timerToBuildInvalidatedProject);
22602260
}
2261-
state.timerToBuildInvalidatedProject = hostWithWatch.setTimeout(buildNextInvalidatedProject, time, state, changeDetected);
2261+
state.timerToBuildInvalidatedProject = hostWithWatch.setTimeout(buildNextInvalidatedProject, time, "timerToBuildInvalidatedProject", state, changeDetected);
22622262
}
22632263

2264-
function buildNextInvalidatedProject<T extends BuilderProgram>(state: SolutionBuilderState<T>, changeDetected: boolean) {
2264+
function buildNextInvalidatedProject<T extends BuilderProgram>(_timeoutType: string, state: SolutionBuilderState<T>, changeDetected: boolean) {
22652265
performance.mark("SolutionBuilder::beforeBuild");
22662266
const buildOrder = buildNextInvalidatedProjectWorker(state, changeDetected);
22672267
performance.mark("SolutionBuilder::afterBuild");

src/compiler/watchPublic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
803803
}
804804
const pending = clearInvalidateResolutionsOfFailedLookupLocations();
805805
writeLog(`Scheduling invalidateFailedLookup${pending ? ", Cancelled earlier one" : ""}`);
806-
timerToInvalidateFailedLookupResolutions = host.setTimeout(invalidateResolutionsOfFailedLookup, 250);
806+
timerToInvalidateFailedLookupResolutions = host.setTimeout(invalidateResolutionsOfFailedLookup, 250, "timerToInvalidateFailedLookupResolutions");
807807
}
808808

809809
function invalidateResolutionsOfFailedLookup() {
@@ -825,7 +825,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
825825
host.clearTimeout(timerToUpdateProgram);
826826
}
827827
writeLog("Scheduling update");
828-
timerToUpdateProgram = host.setTimeout(updateProgramWithWatchStatus, 250);
828+
timerToUpdateProgram = host.setTimeout(updateProgramWithWatchStatus, 250, "timerToUpdateProgram");
829829
}
830830

831831
function scheduleProgramReload() {

src/server/session.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ export function formatMessage<T extends protocol.Message>(msg: T, logger: Logger
329329
* Allows to schedule next step in multistep operation
330330
*/
331331
interface NextStep {
332-
immediate(action: () => void): void;
333-
delay(ms: number, action: () => void): void;
332+
immediate(actionType: string, action: () => void): void;
333+
delay(actionType: string, ms: number, action: () => void): void;
334334
}
335335

336336
/**
@@ -371,22 +371,22 @@ class MultistepOperation implements NextStep {
371371
this.setImmediateId(undefined);
372372
}
373373

374-
public immediate(action: () => void) {
374+
public immediate(actionType: string, action: () => void) {
375375
const requestId = this.requestId!;
376376
Debug.assert(requestId === this.operationHost.getCurrentRequestId(), "immediate: incorrect request id");
377377
this.setImmediateId(this.operationHost.getServerHost().setImmediate(() => {
378378
this.immediateId = undefined;
379379
this.operationHost.executeWithRequestId(requestId, () => this.executeAction(action));
380-
}));
380+
}, actionType));
381381
}
382382

383-
public delay(ms: number, action: () => void) {
383+
public delay(actionType: string, ms: number, action: () => void) {
384384
const requestId = this.requestId!;
385385
Debug.assert(requestId === this.operationHost.getCurrentRequestId(), "delay: incorrect request id");
386386
this.setTimerHandle(this.operationHost.getServerHost().setTimeout(() => {
387387
this.timerHandle = undefined;
388388
this.operationHost.executeWithRequestId(requestId, () => this.executeAction(action));
389-
}, ms));
389+
}, ms, actionType));
390390
}
391391

392392
private executeAction(action: (next: NextStep) => void) {
@@ -1271,7 +1271,7 @@ export class Session<TMessage = string> implements EventSender {
12711271
const goNext = () => {
12721272
index++;
12731273
if (checkList.length > index) {
1274-
next.delay(followMs, checkOne);
1274+
next.delay("checkOne", followMs, checkOne);
12751275
}
12761276
};
12771277
const checkOne = () => {
@@ -1308,7 +1308,7 @@ export class Session<TMessage = string> implements EventSender {
13081308
goNext();
13091309
return;
13101310
}
1311-
next.immediate(() => {
1311+
next.immediate("semanticCheck", () => {
13121312
this.semanticCheck(fileName, project);
13131313
if (this.changeSeq !== seq) {
13141314
return;
@@ -1318,15 +1318,15 @@ export class Session<TMessage = string> implements EventSender {
13181318
goNext();
13191319
return;
13201320
}
1321-
next.immediate(() => {
1321+
next.immediate("suggestionCheck", () => {
13221322
this.suggestionCheck(fileName, project);
13231323
goNext();
13241324
});
13251325
});
13261326
};
13271327

13281328
if (checkList.length > index && this.changeSeq === seq) {
1329-
next.delay(ms, checkOne);
1329+
next.delay("checkOne", ms, checkOne);
13301330
}
13311331
}
13321332

src/server/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ThrottledOperations {
3434
this.host.clearTimeout(pendingTimeout);
3535
}
3636
// schedule new operation, pass arguments
37-
this.pendingTimeouts.set(operationId, this.host.setTimeout(ThrottledOperations.run, delay, this, operationId, cb));
37+
this.pendingTimeouts.set(operationId, this.host.setTimeout(ThrottledOperations.run, delay, operationId, this, cb));
3838
if (this.logger) {
3939
this.logger.info(`Scheduled: ${operationId}${pendingTimeout ? ", Cancelled earlier one" : ""}`);
4040
}
@@ -47,7 +47,7 @@ export class ThrottledOperations {
4747
return this.pendingTimeouts.delete(operationId);
4848
}
4949

50-
private static run(self: ThrottledOperations, operationId: string, cb: () => void) {
50+
private static run(operationId: string, self: ThrottledOperations, cb: () => void) {
5151
perfLogger?.logStartScheduledOperation(operationId);
5252
self.pendingTimeouts.delete(operationId);
5353
if (self.logger) {

src/testRunner/unittests/tsbuildWatch/configFileErrors.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import { verifyTscWatch } from "../tscWatch/helpers";
33
import {
44
createWatchedSystem,
55
libFile,
6-
TestServerHost,
76
} from "../virtualFileSystemWithWatch";
87

98
describe("unittests:: tsbuildWatch:: watchMode:: configFileErrors:: reports syntax errors in config file", () => {
10-
function build(sys: TestServerHost) {
11-
sys.checkTimeoutQueueLengthAndRun(1); // build the project
12-
sys.checkTimeoutQueueLength(0);
13-
}
149
verifyTscWatch({
1510
scenario: "configFileErrors",
1611
subScenario: "reports syntax errors in config file",
@@ -41,25 +36,25 @@ describe("unittests:: tsbuildWatch:: watchMode:: configFileErrors:: reports synt
4136
caption: "reports syntax errors after change to config file",
4237
edit: sys => sys.replaceFileText(`/user/username/projects/myproject/tsconfig.json`, ",", `,
4338
"declaration": true,`),
44-
timeouts: build,
39+
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // build the project
4540
},
4641
{
4742
caption: "reports syntax errors after change to ts file",
4843
edit: sys => sys.replaceFileText(`/user/username/projects/myproject/a.ts`, "foo", "fooBar"),
49-
timeouts: build,
44+
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // build the project
5045
},
5146
{
5247
caption: "reports error when there is no change to tsconfig file",
5348
edit: sys => sys.replaceFileText(`/user/username/projects/myproject/tsconfig.json`, "", ""),
54-
timeouts: build,
49+
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // build the project
5550
},
5651
{
5752
caption: "builds after fixing config file errors",
5853
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({
5954
compilerOptions: { composite: true, declaration: true },
6055
files: ["a.ts", "b.ts"]
6156
})),
62-
timeouts: build,
57+
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // build the project
6358
}
6459
]
6560
});

src/testRunner/unittests/tsbuildWatch/demo.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ describe("unittests:: tsbuildWatch:: watchMode:: with demo project", () => {
5555
caption: "Fix error",
5656
edit: sys => sys.writeFile(coreFiles[0].path, coreFiles[0].content),
5757
timeouts: sys => {
58-
sys.checkTimeoutQueueLengthAndRun(1); // build core
59-
sys.checkTimeoutQueueLengthAndRun(1); // build animals, zoo and solution
60-
sys.checkTimeoutQueueLength(0);
58+
sys.runQueuedTimeoutCallbacks(); // build core
59+
sys.runQueuedTimeoutCallbacks(); // build animals, zoo and solution
6160
},
6261
}
6362
]
@@ -80,10 +79,7 @@ ${coreFiles[1].content}`);
8079
import * as A from '../animals';
8180
${coreFiles[1].content}`),
8281
// build core
83-
timeouts: sys => {
84-
sys.checkTimeoutQueueLengthAndRun(1);
85-
sys.checkTimeoutQueueLength(0);
86-
},
82+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
8783
}
8884
]
8985
});

src/testRunner/unittests/tsbuildWatch/moduleResolution.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
5050
{
5151
caption: "Append text",
5252
edit: sys => sys.appendFile(`/user/username/projects/myproject/project1/index.ts`, "const bar = 10;"),
53-
timeouts: sys => {
54-
sys.checkTimeoutQueueLengthAndRun(1); // build project1 and solution
55-
sys.checkTimeoutQueueLength(0);
56-
}
53+
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // build project1 and solution
5754
},
5855
]
5956
});

src/testRunner/unittests/tsbuildWatch/noEmit.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,13 @@ describe("unittests:: tsbuildWatch:: watchMode:: with noEmit", () => {
2424
caption: "No change",
2525
edit: sys => sys.writeFile(`/user/username/projects/myproject/a.js`, sys.readFile(`/user/username/projects/myproject/a.js`)!),
2626
// build project
27-
timeouts: sys => {
28-
sys.checkTimeoutQueueLengthAndRun(1);
29-
sys.checkTimeoutQueueLength(0);
30-
},
27+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
3128
},
3229
{
3330
caption: "change",
3431
edit: sys => sys.writeFile(`/user/username/projects/myproject/a.js`, "const x = 10;"),
3532
// build project
36-
timeouts: sys => {
37-
sys.checkTimeoutQueueLengthAndRun(1);
38-
sys.checkTimeoutQueueLength(0);
39-
},
33+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
4034
},
4135
],
4236
baselineIncremental: true

src/testRunner/unittests/tsbuildWatch/noEmitOnError.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ describe("unittests:: tsbuildWatch:: watchMode:: with noEmitOnError", () => {
1515
caption,
1616
edit: sys => sys.writeFile(`/user/username/projects/noEmitOnError/src/main.ts`, content),
1717
// build project
18-
timeouts: sys => {
19-
sys.checkTimeoutQueueLengthAndRun(1);
20-
sys.checkTimeoutQueueLength(0);
21-
},
18+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
2219
};
2320
}
2421

2522
const noChange: TscWatchCompileChange = {
2623
caption: "No change",
2724
edit: sys => sys.writeFile(`/user/username/projects/noEmitOnError/src/main.ts`, sys.readFile(`/user/username/projects/noEmitOnError/src/main.ts`)!),
2825
// build project
29-
timeouts: sys => {
30-
sys.checkTimeoutQueueLengthAndRun(1);
31-
sys.checkTimeoutQueueLength(0);
32-
},
26+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
3327
};
3428
verifyTscWatch({
3529
scenario: "noEmitOnError",

0 commit comments

Comments
 (0)