C#, Environment.PhysicalCoreCount
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- operating-systems, performance
Research direction
Start by reviewing the existing Environment.ProcessorCount API and the parallel-loop behavior described in the issue. Define the cross-platform physical-core API and determine how heterogeneous P/E cores should affect scheduling; done requires an agreed scope and validation across the processor configurations named here.
Written by the indexing model from the issue text.
Description
This issue has been moved from a ticket on Developer Community.
Currently, Environment.ProcessorCount provides the total number of logical threads, which has been useful in processors leveraging technologies like SMT (Simultaneous Multithreading). However, this approach has limitations because, in SMT configurations, only one thread per core is truly executed simultaneously, while the second thread is only used when the first thread is idle. This can lead to worse performance in intensive parallel loops (such as those using native memory and pointers) when attempting to use all logical threads without effectively leveraging hardware resources.
Until now, dividing Environment.ProcessorCount by 2 was a common practice to estimate the number of physical cores. However, this solution is no longer valid with newer processors that do not implement SMT, such as some recent Intel and Apple models. In these cases, continuing to divide by 2 would result in a significant waste of resources by ignoring half of the available physical cores.
For this reason, it is crucial for C# to offer a native API to directly retrieve the number of physical cores, something like Environment.PhysicalCoreCount. This would avoid the current limitations and ensure a reliable, cross-platform, and native way to access this information without relying on operating system calls.
Additionally, it is important to revisit how C# parallel loops handle scenarios on heterogeneous processors, i.e., those combining high-performance cores (P-cores) and high-efficiency cores (E-cores), as seen in modern hybrid architectures. In such cases, the performance of parallel loops can degrade significantly if the unequal performance of the cores is not accounted for. A potential solution could involve dynamically adjusting the workload based on the relative performance of each core.
These improvements would not only benefit high-performance scenarios but also simplify the development of applications that need to optimally utilize underlying hardware in modern and heterogeneous configurations.
Original Comments
Feedback Bot on 12/2/2024, 09:22 PM:
Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. You will hear from us in about a week on our next steps.
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·