Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit 441ef99

Browse files
committed
fix: try to fix some places of potential performance degradation, refs #366
1 parent d4ef30a commit 441ef99

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

src/checker/runtime.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
367367

368368
const allDiagnostics = program
369369
.getOptionsDiagnostics().concat(
370-
service.getProgram().getGlobalDiagnostics()
370+
program.getGlobalDiagnostics()
371371
);
372372

373373
const nativeGetter = program.getSourceFiles;
@@ -377,8 +377,8 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
377377
});
378378
}
379379

380-
allDiagnostics.push(...service.getProgram().getSyntacticDiagnostics());
381-
allDiagnostics.push(...service.getProgram().getSemanticDiagnostics());
380+
allDiagnostics.push(...program.getSyntacticDiagnostics());
381+
allDiagnostics.push(...program.getSemanticDiagnostics());
382382

383383
program.getSourceFiles = nativeGetter;
384384

src/checker/send.ts

+27-21
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,48 @@ export interface QueuedSender {
44
send: (msg: any) => void;
55
}
66

7+
const isWindows = /^win/.test(process.platform);
8+
const logOnError = error => { if (error) { console.error(error); } };
9+
710
// Wrapper around process.send() that will queue any messages if the internal node.js
811
// queue is filled with messages and only continue sending messages when the internal
912
// queue is free again to consume messages.
1013
// On Windows we always wait for the send() method to return before sending the next message
1114
// to workaround https://github.com/nodejs/node/issues/7657 (IPC can freeze process)
1215
export function createQueuedSender(childProcess: ChildProcess | NodeJS.Process): QueuedSender {
13-
let msgQueue = [];
14-
let isSending = false;
15-
16-
const doSendLoop = function(): void {
17-
const msg = msgQueue.shift();
18-
19-
childProcess.send(msg, error => {
20-
if (error) {
21-
console.error(error);
22-
}
16+
if (isWindows) {
17+
let msgQueue = [];
18+
let isSending = false;
2319

20+
const cb = error => {
21+
logOnError(error);
2422
if (msgQueue.length > 0) {
2523
setImmediate(doSendLoop);
2624
} else {
2725
isSending = false;
2826
}
29-
});
30-
};
27+
};
3128

32-
const send = function (msg: any): void {
33-
msgQueue.push(msg); // add to the queue if the process cannot handle more messages
29+
const doSendLoop = function(): void {
30+
childProcess.send(msgQueue.shift(), cb);
31+
};
3432

35-
if (isSending) {
36-
return;
37-
}
33+
const send = function (msg: any): void {
34+
msgQueue.push(msg); // add to the queue if the process cannot handle more messages
35+
if (isSending) {
36+
return;
37+
}
3838

39-
isSending = true;
39+
isSending = true;
40+
doSendLoop();
41+
};
4042

41-
doSendLoop();
42-
};
43+
return { send };
44+
} else {
45+
const send = function (msg: any): void {
46+
childProcess.send(msg, logOnError);
47+
};
4348

44-
return { send };
49+
return { send };
50+
}
4551
}

0 commit comments

Comments
 (0)