Replies: 2 comments 1 reply
-
There is already an idea to allow readonlyspan with params. This should give almost same performance since spans do not allocate (you only have to pay for span creation which is much cheaper). However team already has a lot on their plate so this idea ended up in backlog.... https://github.com/dotnet/csharplang/blob/main/proposals/format.md |
Beta Was this translation helpful? Give feedback.
-
I don't think there's any automatic way to generate the body of these methods though. Your example just repeats Console.WriteLine, but real-world examples are rarely this simple. String.Format for example had dedicated infrastructure to accept up to 3 explicit params, and the Task.WhenAny overload which takes 2 tasks has a dedicated 2-task-specific implementation. |
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.
-
When i watched Dotnetos Conference talk about optimizations by Stephen Toub,
I noticed that he mentioned how adding new instances of method
Task.WhenAny
with const parameter lengthsimproved speed by skipping array allocation on method call.
https://youtu.be/Ehvr9wXJNEM?t=1151
dotnet/runtime#34288
So my idea would be to create source generator that would automatically construct and optimize those methods,
and give warning and leave it as is if its not possible to do so.
for example
would generate 2 methods behind the scenes
Beta Was this translation helpful? Give feedback.
All reactions