buybackoff / 1brc

1BRC in .NET among fastest on Linux
https://hotforknowledge.com/2024/01/13/1brc-in-dotnet-among-fastest-on-linux-my-optimization-journey/
MIT License
437 stars 43 forks source link

Some ideas of improvements #5

Closed oleggolovkov closed 8 months ago

oleggolovkov commented 8 months ago

I was looking at the code and thought there are some things worth trying to further improve the execution time:

buybackoff commented 8 months ago

pass Summary by ref to Merge

Everything besides ProcessChunk has near zero impact on performance

Summary is 16 bytes and for min/max int is not needed, short should be enough.

Thanks, I did that after your original comment. It was helpful to reduce the struct size to 16 bytes.

.Select(x => (Name: x.Key.ToString(), x.Value)) for final result may not be needed, instead Utf8Span could implement IComparable and do comparison on Span property

Again, doesn't matter. I need to materialize the span at some point, it's better to just use string sort. Then I reuse the same strings for printing,

The rest is really not relevant for performance, it happens only once.

oleggolovkov commented 8 months ago

I need to materialize the span at some point

why? I think it should be possible to just print span to console

The rest is really not relevant for performance, it happens only once.

yes but it depends on the number of unique cities and if we combine overhead of ToList, allocations caused by OrderBy (btw we could sort this with Radix sort in O(N)) it may be noticeable

buybackoff commented 8 months ago

yes but it depends on the number of unique cities and if we combine overhead of ToList, allocations caused by OrderBy (btw we could sort this with Radix sort in O(N)) it may be noticeable

Oh, please. Profile it before suggesting. It's becoming boring.

oleggolovkov commented 8 months ago

The problem is there is no exact data set to profile, of course for the sample in the original repo with like 80 cities there would be no difference, however it was mentioned that we can not make any assumptions about the data and if all 1B rows have distinct cities it is obvious there will be a difference

buybackoff commented 8 months ago

Everything is 100% reproducible... I cannot even imagine which step could be difficult even for a total noob. Both Java repo (with its instructions), and this plain vanilla repo with script showing which commands to call.

Profiling is built into free IDEs.