-
Notifications
You must be signed in to change notification settings - Fork 49
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
Significantly improve .NET's code #8
base: main
Are you sure you want to change the base?
Conversation
- Updated to .NET 7 - Dropped `ImplicitUsings` in dotnet.csproj - Uses an array of Task[] over a list of List<Task> to prevent constant resizing of the internally backed array. - Dropped Task.Run and passes the Task itself in the for loop.
You added bin and obj folders. |
Whoops! You're right |
Good job @OoLunar , I agree your correcations. |
in fact would be better to use top-level statements to show beauty of modern c# for the doubters hehe my code would look like this:
|
And also do top level namespace |
Have either one of y'all benchmarked your new code? While I agree, the code could look appealing to non-C# users, the goal here is to provide efficiency, not readability.
What... do you think an enumerable is, and how do you think it is internally represented? Arrays are quite efficient upon iteration, indexing and long lifetimes. Enumerables are a read-only interface which hides implementation from user. The goal here is to create X amount of tasks and wait for all of them to finish executing, thus there is no reason to hide the implementation via enumerables since we are the only people who are able to access the implementation. |
@OoLunar of course i did benchmark different solutions, as far as i remember there was no noticeable difference between your and my code, but original code was somewhat inefficient. |
There's no noticeable difference because the bulk of the benchmark is waitinh on the tasks to complete, however, in a less contrived and more realistic scenario, LINQ vs manual construction can make a huge difference - and if your goal is to showcase efficient C# code, using an infamous performance hog (LINQ) doesn't accomplish that. |
@akiraveliara my goal is to create readable & efficient code for this particular problem. i know linq can be expensive in some cases, but it does not bother me as it really does not matter in this context |
This particular problem does not require readable code, it requires efficient code. You are welcome to create a separate pull request if you believe otherwise. |
if your goal is to write both readable and efficient code you failed in both departments |
Significantly improves .NET's code, closes #4
ImplicitUsings
indotnet.csproj
Task[]
) over a list (List<Task>
) to prevent constant resizing of the internally backed array.Task.Run
and passes theTask
itself in the for loop. This prevents the unnecessary creation of an additional async contexts.Additionally
ValueTask
s are typically used in hotpaths overTask
's due to their newer implementation and don't suffer the scars of .NET framework.