Proposal: Modern IEnumerable<T> abstraction #2053
Replies: 8 comments
-
The design seems a lot more complicated and significantly more limited compared to what you can do with enumerators today. Basing it on |
Beta Was this translation helpful? Give feedback.
-
I have updated the topic with usag example.
|
Beta Was this translation helpful? Give feedback.
-
The concept of "write-only" doesn't exist in .NET.
Stack allocation of managed types is being explored by the CLR team, but as an optimization within the JIT. Managed languages won't be able to request this. It requires that the JIT can perform escape analysis on all of the code to which the instance will be passed, which is impossible to do at the compiler level. You also have the problem of this pattern being entirely unsuitable for iterators due to the use of Requiring multiple CLR changes for a single language change which only seeks to duplicate existing functionality seems unlikely, at best. What's worse, your enumeration pattern requires a second enumeration over the span. |
Beta Was this translation helpful? Give feedback.
-
I understand that right now nothing is ready for this pattern, but it's about performance (and it's a long-run target). It's a matter of time to prove that many things are solvable. It's better to say currently this feature requeres too many expensive changes. |
Beta Was this translation helpful? Give feedback.
-
I think you're dramatically over-estimating the cost of the existing abstractions. At worst, the existing abstractions incur an overhead of a few nanoseconds per iteration. Modern processors are very efficient and the current JIT compilers are very good at making effective use of those processors. If you had a really tight loop that was iterating over a million items, it's possible that the proposed abstractions would save a few milliseconds of execution time. If the body of the loop is doing any non-trivial computation, any potential saving will be drowned in the statistical noise of measurement. There are any number of other performance improving proposals (including the linked JIT stack allocation of objects) that will have a performance impact that's literally orders of magnitude greater. Better algorithms always trump micro-optimizations. |
Beta Was this translation helpful? Give feedback.
-
This might be of interest: dotnet/corefx#34208 |
Beta Was this translation helpful? Give feedback.
-
Abstractions usually come with a cost. In performance-critical parts implementations are used directly |
Beta Was this translation helpful? Give feedback.
-
@declard Examples: #2904 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
Current
IEnumerable<T>
abstraction have couple of performance issues:Also this abstraction is derived from legacy
IEnumerable
(pre-generics era of C#) that have very rare usage.Proposal
IEnumerable2<T>
provides the next improvements over currentIEnumerable<T>
:Other related questions:
Probably it's possible join in a single abstraction: 1) Enumeration and 2) Sync/Async channel reader.
Beta Was this translation helpful? Give feedback.
All reactions