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

Improve how to retrieve process ID #3794

Merged
merged 2 commits into from
Jun 22, 2022
Merged

Conversation

Evangelink
Copy link
Member

@@ -65,7 +65,14 @@ internal class ArtifactProcessingManager : IArtifactProcessingManager
{
_testSessionCorrelationId = testSessionCorrelationId;
_processArtifactFolder = Path.Combine(_fileHelper.GetTempPath(), _testSessionCorrelationId);
_testSessionProcessArtifactFolder = Path.Combine(_processArtifactFolder, $"{Process.GetCurrentProcess().Id}_{Guid.NewGuid()}");
#if NET5_0_OR_GREATER
var pid = Environment.ProcessId;
Copy link
Contributor

@MarcoRossignoli MarcoRossignoli Jun 22, 2022

Choose a reason for hiding this comment

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

is it cached by design?

Copy link
Member Author

Choose a reason for hiding this comment

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

System.Diagnostics.Process.GetCurrentProcess().Id is expensive:

It allocates a Process instance, usually just to get the Id.
The Process instance needs to be disposed, which has a performance impact.
It's easy to forget to call Dispose() on the Process instance.
If nothing else besides Id uses the Process instance, then the linked size grows unnecessarily by increasing the graph of types referenced.
It is somewhat difficult to discover or find this API.
System.Environment.ProcessId avoids all the above.

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.

2 participants