Skip to content

Commit 5e672b7

Browse files
CyrusNajmabadivladima
authored andcommitted
Don't log by default.
On the managed side tracing is disabled by default anyways. By logging we still cause tons of allocations of strings on the managed side. These then cause expensive GCs which can pause editing.
1 parent 937927a commit 5e672b7

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/services/shims.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,22 @@ module ts {
246246

247247
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {
248248
private files: string[];
249+
private loggingEnabled = false;
250+
private tracingEnabled = false;
249251

250252
constructor(private shimHost: LanguageServiceShimHost) {
251253
}
252254

253255
public log(s: string): void {
254-
this.shimHost.log(s);
256+
if (this.loggingEnabled) {
257+
this.shimHost.log(s);
258+
}
255259
}
256260

257261
public trace(s: string): void {
258-
this.shimHost.trace(s);
262+
if (this.tracingEnabled) {
263+
this.shimHost.trace(s);
264+
}
259265
}
260266

261267
public error(s: string): void {
@@ -349,15 +355,15 @@ module ts {
349355
}
350356
}
351357

352-
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, noPerfLogging: boolean): any {
353-
if (!noPerfLogging) {
358+
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any {
359+
if (logPerformance) {
354360
logger.log(actionDescription);
355361
var start = Date.now();
356362
}
357363

358364
var result = action();
359365

360-
if (!noPerfLogging) {
366+
if (logPerformance) {
361367
var end = Date.now();
362368
logger.log(actionDescription + " completed in " + (end - start) + " msec");
363369
if (typeof (result) === "string") {
@@ -372,9 +378,9 @@ module ts {
372378
return result;
373379
}
374380

375-
function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, noPerfLogging: boolean): string {
381+
function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): string {
376382
try {
377-
var result = simpleForwardCall(logger, actionDescription, action, noPerfLogging);
383+
var result = simpleForwardCall(logger, actionDescription, action, logPerformance);
378384
return JSON.stringify({ result: result });
379385
}
380386
catch (err) {
@@ -413,6 +419,7 @@ module ts {
413419

414420
class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim {
415421
private logger: Logger;
422+
private logPerformance = false;
416423

417424
constructor(factory: ShimFactory,
418425
private host: LanguageServiceShimHost,
@@ -422,7 +429,7 @@ module ts {
422429
}
423430

424431
public forwardJSONCall(actionDescription: string, action: () => any): string {
425-
return forwardJSONCall(this.logger, actionDescription, action, /*noPerfLogging:*/ false);
432+
return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance);
426433
}
427434

428435
/// DISPOSE
@@ -811,6 +818,7 @@ module ts {
811818

812819
class ClassifierShimObject extends ShimBase implements ClassifierShim {
813820
public classifier: Classifier;
821+
private logPerformance = false;
814822

815823
constructor(factory: ShimFactory, private logger: Logger) {
816824
super(factory);
@@ -820,7 +828,7 @@ module ts {
820828
public getEncodedLexicalClassifications(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string {
821829
return forwardJSONCall(this.logger, "getEncodedLexicalClassifications",
822830
() => convertClassifications(this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)),
823-
/*noPerfLogging:*/ true);
831+
this.logPerformance);
824832
}
825833

826834
/// COLORIZATION
@@ -838,13 +846,14 @@ module ts {
838846
}
839847

840848
class CoreServicesShimObject extends ShimBase implements CoreServicesShim {
849+
private logPerformance = false;
841850

842851
constructor(factory: ShimFactory, public logger: Logger, private host: CoreServicesShimHostAdapter) {
843852
super(factory);
844853
}
845854

846855
private forwardJSONCall(actionDescription: string, action: () => any): any {
847-
return forwardJSONCall(this.logger, actionDescription, action, /*noPerfLogging:*/ false);
856+
return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance);
848857
}
849858

850859
public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {

0 commit comments

Comments
 (0)