News for hackers. Stuff that matters.

Show HN: hist: An overengineered solution to `sort|uniq -c` with 25x throughput

https://github.com/noamteyssier/hist-rs

Was sitting around in meetings yesterday and remembered an old shell script I had to count the number of unique lines in a file. Gave it a shot in rust and with a little bit of (over-engineering)™ I managed to get 25x throughput over the naive approach using coreutils as well as improve over some existing tools.

Some notes on the improvements:

1. using csv (serde) for writing leads to some big gains

2. arena allocation of incoming keys + storing references in the hashmap instead of storing owned values heavily reduced the number of allocations and improves cache efficiency (I'm guessing, I did not measure).

There are some regex functionalities and some table filtering built in as well.

happy hacking

( 5 comments | 3 points | on HN )
Re:Show HN: hist: An overengineered solution to `sort|uniq -... by southwindcg on Thursday October 23, 2025 @01:24PM (#45684433)
I don't [currently?] have a use case for this tool, but I love seeing existing tools made faster or more efficient.
Re:Show HN: hist: An overengineered solution to `sort|uniq -... by noamteyssier on Thursday October 23, 2025 @01:39PM (#45684584)
I think that it's a pretty common use case for text processing - I end up needing to use it a lot in bioinformatics where there is a lot of text processing.

It's great when you quickly need to see what the distribution of classes in an input stream is. This pops up all the time. Like measuring different types of log messages, counting the variants of a field in a csv, finding the most common word or substring, etc.

Re:Show HN: hist: An overengineered solution to `sort|uniq -... by southwindcg on Thursday October 23, 2025 @02:55PM (#45685410)
Oh, I meant me, personally, I don't have a use case for it. Without a doubt a lot of people are going to find this speed improvement valuable.
Re:Show HN: hist: An overengineered solution to `sort|uniq -... by mfld on Friday October 24, 2025 @03:50AM (#45692018)
Nice - thanks! I assume the non-naive implementations skip the sorting and instead hash the input lines?
Re:Show HN: hist: An overengineered solution to `sort|uniq -... by noamteyssier on Tuesday October 28, 2025 @02:34PM (#45736888)
yeah that's right - there are trade-offs in doing so as it can require much more memory. So like everything it's an application specific decision