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

Avoid unnecessary closures/delegates in Process #50496

Merged
merged 1 commit into from
Apr 7, 2021

Conversation

stephentoub
Copy link
Member

No description provided.

@ghost
Copy link

ghost commented Mar 31, 2021

Tagging subscribers to this area: @carlossanlop
See info in area-owners.md if you want to be subscribed.

Issue Details
Author: stephentoub
Assignees: -
Labels:

area-System.Diagnostics.Process

Milestone: -

{
return Id == possibleChildProcess.ParentProcessId;
}
catch (Exception e) when (IsProcessInvalidException(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the code also be changed to not use exception filters

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with @jkotas that going through and removing exception filters is a step in the wrong direction.
#50281 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the benefit of using generic Exception with filters over catch for specific exceptions?

Copy link
Member Author

Choose a reason for hiding this comment

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

All of the places that handle these exceptions then need to duplicate the list. And each of them needs its own catch block with the logic duplicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that only hides the real problem here. The better improvement would be not to use exceptions for normal flow execution here. For example by changing ParentProcessId to return int? and catch the only exceptions which can really happen on specific platforms instead of generic IsProcessInvalidException.

Copy link
Member Author

Choose a reason for hiding this comment

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

The better improvement would be not to use exceptions for normal flow execution here.

It's not using exceptions for "normal flow" here. It's using exceptions for exceptional situations, e.g. a race condition between a process being alive one moment and then not the next. Making a blanket statement that exceptions shouldn't be used for control flow is akin to saying code should never have a try/catch and all throws should instead be fail-fasts. That ship sailed over two decades ago.

It's also entirely orthogonal to this PR. This PR is not introducing any new exceptions in any new places, nor is it eating exceptions any more or any less than before. It's only changing the manner in which those same exceptions are caught.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also entirely orthogonal to this PR.

Fair enough. I didn't want to block this just pointing out possible better implementation. I might give it a shot once this lands.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

Which tool have you used to identify the unnecessary closures? Have you considered using it for the entire runtime repo and creating new up-for-grabs issues to get rid of all removable closures in the entire BCL?

@stephentoub
Copy link
Member Author

Which tool have you used to identify the unnecessary closures?

ILSpy, searching for DisplayClass across all of netcoreapp, and then walking through them looking for ones that looked easily avoidable / unnecessary / mistakes.

to get rid of all removable closures in the entire BCL?

I don't think a tool can say whether a closure should be removed or not; sometimes they're the right tool for the job. It becomes a judgement call around ease of removal / maintenance impact, performance benefits/costs, and hotness of the path.

I submitted a handful of PRs to fix the ones across netcoreapp that on quick look met my threshold:
#50512
#50511
#50502
#50496
#50487
#50483
#50387
#50377
#50376
#50357

@stephentoub stephentoub merged commit bc7cf1c into dotnet:main Apr 7, 2021
@stephentoub stephentoub deleted the processclosure branch April 7, 2021 11:58
thaystg added a commit to thaystg/runtime that referenced this pull request Apr 7, 2021
* upstream/main: (568 commits)
  [wasm] Set __DistroRid on Windows to browser-wasm (dotnet#50842)
  [wasm] Fix order of include paths, to have the obj dir first (dotnet#50303)
  [wasm] Fix debug build of AOT cross compiler (dotnet#50418)
  Fix outdated comment (dotnet#50834)
  [wasm][tests] Add properties to allow passing args to xharness (dotnet#50678)
  Vectorized common String.Split() paths (dotnet#38001)
  Fix binplacing symbol files. (dotnet#50819)
  Move type check to after the null ref branch in out marshalling of blittable classes. (dotnet#50735)
  Remove extraneous CMake version requirement. (dotnet#50805)
  [wasm] Remove unncessary condition for EMSDK (dotnet#50810)
  Add loop alignment stats to JitLogCsv (dotnet#50624)
  Resolve ILLink warnings in System.Diagnostics.DiagnosticSource (dotnet#50265)
  Avoid unnecessary closures/delegates in Process (dotnet#50496)
  Fix for field layout verification across version bubble boundary (dotnet#50364)
  JIT: Enable CSE for VectorX.Create (dotnet#50644)
  [main] Update dependencies from mono/linker (dotnet#50779)
  [mono] More domain cleanup (dotnet#50771)
  Race condition in Mock reference tracker runtime with GC. (dotnet#50804)
  Remove IAssemblyName (and various fusion remnants) (dotnet#50755)
  Disable failing test for GCStress. (dotnet#50828)
  ...
@ghost ghost locked as resolved and limited conversation to collaborators May 7, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants