Skip to content

Speed up Write-Host#2674

Merged
daxian-dbw merged 2 commits into
PowerShell:masterfrom
lzybkr:write-host-speedup
Nov 14, 2016
Merged

Speed up Write-Host#2674
daxian-dbw merged 2 commits into
PowerShell:masterfrom
lzybkr:write-host-speedup

Conversation

@lzybkr
Copy link
Copy Markdown
Contributor

@lzybkr lzybkr commented Nov 12, 2016

Write-Host is creating an InformationRecord.

As part of the initialization of InformationRecord, we were initializing the ComputerName property.

This is apparently expensive, so I deferred initializing the value until the first time the property is accessed, which is uncommon, but will happen during remoting (because all properties are serialized).

In my local runs, CI tests ran much faster, 254s with the change, 305s without. A similar improvement is seen in calling Write-Host repeatedly - 2.2s for 4000 calls with the change, 47s without.

An InformationRecord instance is created when calling Write-Host,
but many of the properties aren't read.

It can be expensive to initialize some of those properties, so
the code has been changed to initialize those properties on first access.
Copy link
Copy Markdown
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lzybkr lzybkr force-pushed the write-host-speedup branch from 30b2350 to bbbc409 Compare November 14, 2016 18:54
@vors vors closed this Nov 14, 2016
@vors vors reopened this Nov 14, 2016
@lzybkr
Copy link
Copy Markdown
Contributor Author

lzybkr commented Nov 14, 2016

Assigning to @daxian-dbw to merge.

@daxian-dbw daxian-dbw merged commit ca2dce3 into PowerShell:master Nov 14, 2016
@lzybkr lzybkr deleted the write-host-speedup branch November 14, 2016 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants