Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf nit in spdlogService.ts #39808

Closed
jrieken opened this issue Dec 6, 2017 · 1 comment
Closed

Perf nit in spdlogService.ts #39808

jrieken opened this issue Dec 6, 2017 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug log VS Code log issues perf verified Verification succeeded
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

re #39572

In SpdLogService you could save a few arrays and iterations by not declaring var-args but by using the the gold old arguments-objects. In pretty TS we have this trace(message: string, ...args: any[]):void which, thanks to ES5, thanks to IE11, will be downlevel compiled to

SpdLogService.prototype.trace = function (message) {
            var args = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                args[_i - 1] = arguments[_i];
            }

Every time one of the log methods is being called (1) a new array is being allocated and (2) the arguments are iterated once. Changing the TypeScript to trace():void will still compile. You would simply pass the arguments object to the format-method. Like so

trace(): void {
	if (this.level <= LogLevel.Trace) {
		this.logger.trace(this.format(arguments));
	}
}

//..
private format(args:IArguments): string {
  //...
}
@vscodebot vscodebot bot assigned mjbvz Dec 6, 2017
@vscodebot vscodebot bot added the javascript JavaScript support issues label Dec 6, 2017
@jrieken jrieken assigned joaomoreno and unassigned mjbvz Dec 6, 2017
@joaomoreno joaomoreno added this to the November 2017 milestone Dec 6, 2017
@joaomoreno joaomoreno added bug Issue identified by VS Code Team member as probable bug log VS Code log issues perf and removed javascript JavaScript support issues labels Dec 6, 2017
@jrieken
Copy link
Member Author

jrieken commented Dec 6, 2017

Oh, and the format function itself can save two arrays and one array-iteration by just incrementally building the string it returns

@jrieken jrieken added the verified Verification succeeded label Dec 7, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug log VS Code log issues perf verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants