# Sorting Strings in Rust: Why Allocating Lowercase Strings Beats Lazy Comparison

Original title: Matching Puzzle Pieces and Disappointing Benchmarks

> Hacker News story 49554848 · language: en · submitted 2026-09-03
> Web version: https://zeli.app/story/49554848
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 6 · by [speckx](<https://news.ycombinator.com/user?id=speckx>) · 💬 0
[original](<https://llogiq.github.io/2026/03/20/case.html>) · [HN discussion](<https://news.ycombinator.com/item?id=49554848>)

## Summary

A Rust developer benchmarks three ways to case-insensitively sort strings: pre-computing lowercase with `sort_by_cached_key`, lazily converting during comparison with `sort_by` and `flat_map`, and using the `unicase` crate. Tests on an M2 Max show that despite extra allocations, `sort_by_cached_key` wins for lists of 5 or more, while `unicase` surprisingly outperforms both for larger inputs, revealing that lazy conversion overhead outweighs allocation costs.

## Key quote

> The real surprise is that Unicase can often be faster, despite making the comparison more complex.

---

## Cite

- Page: https://zeli.app/story/49554848
- Date: 2026-09-03
- Source: llogiq.github.io (https://llogiq.github.io/2026/03/20/case.html)
- Hacker News: https://news.ycombinator.com/item?id=49554848

## Other languages

- zh: https://zeli.app/zh/story/49554848 · markdown: https://zeli.app/zh/story/49554848.md
- ja: https://zeli.app/ja/story/49554848 · markdown: https://zeli.app/ja/story/49554848.md
- ko: https://zeli.app/ko/story/49554848 · markdown: https://zeli.app/ko/story/49554848.md
- de: https://zeli.app/de/story/49554848 · markdown: https://zeli.app/de/story/49554848.md
- es: https://zeli.app/es/story/49554848 · markdown: https://zeli.app/es/story/49554848.md
- ru: https://zeli.app/ru/story/49554848 · markdown: https://zeli.app/ru/story/49554848.md
