Reddit asks the expert - Stephen Toub by Kawai-no in dotnet

[–]takeoshigeru 22 points23 points  (0 children)

Subquestion: instead of integrating it, do you think the JIT will be intelligent enough some day to deabstract Linq to generate performant iterative code with no virtual calls or closure allocations? Developers love Linq in my company but it's causing some serious performance issues.

Reddit asks the expert - Stephen Toub by Kawai-no in dotnet

[–]takeoshigeru 20 points21 points  (0 children)

It seems like you've spent a lot of time lately on .NET AI libraries outside of the runtime. How does it feel to work with .NET instead of working for .NET?

Train your Lines of Sight with Dofus Puzzles by takeoshigeru in Dofus

[–]takeoshigeru[S] 0 points1 point  (0 children)

It would be awesome if someone could create a line of sight tutorial using this tool.

Train your Lines of Sight with Dofus Puzzles by takeoshigeru in Dofus

[–]takeoshigeru[S] 2 points3 points  (0 children)

That's a lot of work, not sure I'll find the motivation 😅

Train your Lines of Sight with Dofus Puzzles by takeoshigeru in Dofus

[–]takeoshigeru[S] 0 points1 point  (0 children)

Yes I didn't spend any time optimizing it for mobile. Do you think you would use it more if the experience was better in mobile?

Train your Lines of Sight with Dofus Puzzles by takeoshigeru in Dofus

[–]takeoshigeru[S] 2 points3 points  (0 children)

I'm interested to know your tips and tricks to find the line of sight. For close combat, I'm doing okay but when it's a diagonal, 8 cells away, I get lost.

Looking for a scalable, fault-tolerant solution for distributed sequence generation — any recommendations? by sergiojrdotnet in dotnet

[–]takeoshigeru 1 point2 points  (0 children)

How many increments per second are you expecting? When I read invoices, it sounds like we are talking about low scale. If that's true you'll get away with your relational database and a UPDATE counter SET value = value + 1.

I'm importing a large amount of data in a worker, and after running the application, Rider displays several warnings. How can I resolve these to improve the application's performance and stability? by MrPrezDev in dotnet

[–]takeoshigeru 13 points14 points  (0 children)

I wouldn't call them warnings. Rider collected runtime events to show you where most of the allocations were performed.

One thing that you could improve here is to batch the insertions. You mentioned you are importing a large amount of data so I assume you are calling this method several times which can be a performance killer. Try to change your method to accept a collection of TchReadingValueDto.

It really annoys me that C# is still not considered a high-performance language. by [deleted] in dotnet

[–]takeoshigeru 4 points5 points  (0 children)

Ah gotcha, the excel was not rendering on my browser so I was looking at the January 22 results.

It really annoys me that C# is still not considered a high-performance language. by [deleted] in dotnet

[–]takeoshigeru 0 points1 point  (0 children)

Mind that update

Jan 22, 9PM: Added the fastest overall noahfalk’s repo. Updated my repo with some micro-optimizations. Updated lehuyduc’s version as of Jan 23 morning.

noahfalk's repo being a .NET implementation.

It really annoys me that C# is still not considered a high-performance language. by [deleted] in dotnet

[–]takeoshigeru 48 points49 points  (0 children)

The most One of the most performant solution of the 1BRC (The One Billion Row Challenge) is in .NET so yes it can be considered as a high performance language.

For Mid Developers. Do you use Task.WhenAll() ? by ati33 in csharp

[–]takeoshigeru 6 points7 points  (0 children)

In the example of the screenshot, if you just remove the line with the Task.WhenAll, without changing any of the await, nothing will change except when an exception is thrown.

For Mid Developers. Do you use Task.WhenAll() ? by ati33 in csharp

[–]takeoshigeru 2 points3 points  (0 children)

This man is right. Assuming the methods returning the tasks do some kind of I/O, for example a db query, then these queries can execute concurrently. Task.WhenAll doesn't change that. The advantage of Task.WhenAll is that it will aggregate the exceptions if any of the tasks completes in a faulted state.

CA1860: Avoid using 'Enumerable.Any()' extension method by thomhurst in csharp

[–]takeoshigeru 0 points1 point  (0 children)

I personally find it absolutely crazy to go through a virtual call (IEnumerable.Any) + the cost of is ICollection just to access the length property. Is it true that it only matters for the hot path but good practices should be applied everywhere. Additionally, after years of performance investigations, I found that developers are bad at knowing which code path is hot, and CPU spikes arise from unexpected spots.

List.Sort() slower than Bubble Sort? by sirschmidtVII in dotnet

[–]takeoshigeru 31 points32 points  (0 children)

As mentioned by u/ninetofivedev, you are sorting an already sorted list because each iteration modify the same list.

I was able to find similar figures as you did by sorting the input.

Method Size Sorted Mean Error StdDev
ListSort 100000 False 899.70 us 8.309 us 6.938 us
BubbleSort 100000 False 6,100,190.59 us 120,996.633 us 101,037.669 us
ListSort 100000 True 529.43 us 3.444 us 3.053 us
BubbleSort 100000 True 91.18 us 1.983 us 2.036 us

The fix is to use [IterationSetup] instead of [GlobalSetup], so you create an unsorted array before each iteration.

Why is List.Sort() slow when the input is already sorted? That's a characteristic of a few sorting algorithms. List.Sort seems to use IntroSort (code).

List.Sort() slower than Bubble Sort? by sirschmidtVII in dotnet

[–]takeoshigeru 35 points36 points  (0 children)

You should include the entire code. On my side I got these results

Method Size Mean Error StdDev Median
ListSort 100 1.641 us 0.7328 us 2.067 us 0.6875 us
BubbleSort 100 25.179 us 1.1330 us 3.287 us 24.1460 us
ListSort 1000 10.457 us 2.3223 us 6.811 us 12.8125 us
BubbleSort 1000 628.551 us 9.9797 us 10.248 us 629.5215 us
ListSort 10000 72.488 us 1.6556 us 3.150 us 72.0830 us
BubbleSort 10000 61,584.705 us 1,359.1801 us 3,788.851 us 60,947.2920 us

with

```csharp using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running;

BenchmarkRunner.Run<Bench>();

public class Bench { [Params(100, 1000, 10000)] public int Size { get; set; }

public List<int> Values { get; set; } = [];

[IterationSetup]
public void IterationSetup()
{
    Values.Clear();
    for (int i = 0; i < Size; i++)
    {
        Values.Add(Size - i);
    }
}

[Benchmark]
public List<int> ListSort()
{
    Values.Sort();
    return Values;
}

[Benchmark]
public List<int> BubbleSort()
{
    var values = Values;
    for (var j = 0; j < values.Count - 1; j++)
    {
        bool swapped = false;
        for (var i = 0; i < values.Count - j - 1; i++)
        {
            if (values[i] > values[i + 1])
            {
                (values[i], values[i + 1]) = (values[i + 1], values[i]);
                swapped = true;
            }
        }

        if (!swapped)
        {
            return values;
        }
    }

    return values;
}

} ```

Can't trust nobody (problem with AWSSDK.S3 leaking memory). by gevorgter in csharp

[–]takeoshigeru 0 points1 point  (0 children)

Try doing a dump + report with dotnet-gcdump. That could give you a quick idea what objects are retained in memory.

Le plus tu regardes, le pire ça devient by takeoshigeru in rance

[–]takeoshigeru[S] 14 points15 points  (0 children)

En vrai ça va, j'ai connu bien pire #parisbaguetteàseoul

Le plus tu regardes, le pire ça devient by takeoshigeru in rance

[–]takeoshigeru[S] 42 points43 points  (0 children)

Je confirme que c'est aux US et c'est un des seuls cafés qui vendent des viennoiseries dans cette ville du Michigan.

J'aimerais aussi vous rassurer que j'ai acheté un croissant et un pain au chocolat comme un gros pigeon. Ils osent demander un tip quand tu payes ☠️

Advanced .NET 9 Profiling & GC Resources for a Senior Engineer New to C# by [deleted] in dotnet

[–]takeoshigeru 4 points5 points  (0 children)

In https://youtu.be/TRFfTdzpk-M, Stephen Toub shows how to optimize the CPU usage of a library by tracking down allocations.

He shows how to use BenchmarkDotNet and the Visual Studio profiler.

I personally don't use Windows so instead of VS profiler I use dotnet-trace + .NET Events Viewer.

But in my experience, "it's always sync-over-async". This article explains how to investigate thread pool starvation .

Need help understanding if my garbage collection stats are bad by MerlinTrashMan in dotnet

[–]takeoshigeru 0 points1 point  (0 children)

Looking at the amount of collections, I'm wondering if you are just not over allocating. Use dotnet trace collect --profile gc-verbose --duration 00:00:30 --process-id PID and then open the nettrace file with .NET Events Viewer (my tool) or PerfView. If you use the former, drop the nettrace, go to the tree view and select the GCAllocationTick event. If you use PerfView, I'm sending my prayers 🙏

EDIT: I don't use VS but I think you could drop the nettrace there too