Skip to content

Reduce minor allocations at runspace creation time - #10803

Closed
Ilya (iSazonov) wants to merge 1 commit into
PowerShell:masterfrom
iSazonov:perf-create-runspace-1
Closed

Ilya (iSazonov) wants to merge 1 commit into
PowerShell:masterfrom
iSazonov:perf-create-runspace-1

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Oct 16, 2019 •

Copy link
Copy Markdown
Collaborator

PR Summary

  • Use internal PSPropertySet() constructor without checks for null and empty property names
  • Initialize Collection with List which is created with explicit size (reduce re-allocations when add new items).

PR Context

Test script:

measure-Command {
for ($i=0; $i -lt 500; $i++) {
    [runspace] $rs = [runspacefactory]::CreateRunspace()
    $rs.Open()
    $rs.Close()
    if ($null -ne $rs) { $rs.Dispose() }
}
}

Allocations before:
image

Allocations after:
image

PR Checklist

@iSazonov Ilya (iSazonov) added the CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log label Oct 16, 2019
@iSazonov Ilya (iSazonov) added this to the 7.0.0-preview.5 milestone Oct 16, 2019
@TravisEz13

Copy link
Copy Markdown
Member

Dongbo Wang (@daxian-dbw) Can you review?

@daxian-dbw

Copy link
Copy Markdown
Member

This optimization has been done by my TypeTable change #10898, which as been merged. This PR can be closed now.

@iSazonov
Ilya (iSazonov) deleted the perf-create-runspace-1 branch November 2, 2019 06:52
@daxian-dbw Dongbo Wang (daxian-dbw) removed this from the 7.0.0-preview.6 milestone Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants