August 24th, 2024

The Treacherous Optimization (2006)

The author attempts to optimize Hex Fiend's string searching to surpass grep's performance but initially fails. They adopt grep's optimization technique, achieving slight improvements while questioning the trade-offs involved.

Read original articleLink Icon
The Treacherous Optimization (2006)

The article discusses the author's attempt to optimize the string searching capabilities of Hex Fiend, a hex editor, to outperform the well-known tool grep. The author sets an ambitious goal to exceed grep's performance by 30% but initially finds that their implementation is significantly slower. They explore the Boyer-Moore algorithm for string searching, which allows for skipping sections of the text based on mismatches. Despite their efforts, including vectorization and loop unrolling, the author struggles to match grep's speed. Eventually, they discover that grep employs a "treacherous optimization" technique that sacrifices performance in worst-case scenarios for better average-case performance. By adopting a similar approach, the author manages to improve Hex Fiend's performance slightly, but they reflect on the trade-offs involved in such optimizations. The article concludes with a contemplation of whether the benefits of this optimization are worth the potential drawbacks in performance during less favorable conditions.

- The author aimed to optimize Hex Fiend's string searching to outperform grep.

- Initial attempts using the Boyer-Moore algorithm resulted in slower performance than grep.

- Grep's optimization technique improves average-case performance at the cost of worst-case performance.

- The author successfully implements a similar optimization, achieving a slight performance gain.

- The article raises questions about the value of optimization strategies that may compromise performance in certain scenarios.

Related

Optimizing JavaScript for Fun and for Profit

Optimizing JavaScript for Fun and for Profit

Optimizing JavaScript code for performance involves benchmarking, avoiding unnecessary work, string comparisons, and diverse object shapes. JavaScript engines optimize based on object shapes, impacting array/object methods and indirection. Creating objects with the same shape improves optimization, cautioning against slower functional programming methods. Costs of indirection like proxy objects and function calls affect performance. Code examples and benchmarks demonstrate optimization variances.

Some Tricks from the Scrapscript Compiler

Some Tricks from the Scrapscript Compiler

The Scrapscript compiler implements optimization tricks like immediate objects, small strings, and variants for better performance. It introduces immediate variants and const heap to enhance efficiency without complexity, seeking suggestions for future improvements.

Unsafe Read Beyond of Death

Unsafe Read Beyond of Death

The article details the "Unsafe Read Beyond of Death" optimization for the GxHash algorithm, enhancing performance through SIMD instructions and achieving over tenfold speed increases for small payloads while ensuring safety.

Strlcpy and how CPUs can defy common sense

Strlcpy and how CPUs can defy common sense

The article compares the performance of `strlcpy` in OpenBSD and glibc, revealing glibc's faster execution despite double traversal, emphasizing instruction-level parallelism and advocating for sized strings for efficiency.

I sped up serde_json strings by 20%

I sped up serde_json strings by 20%

The author improved the performance of the Rust serialization framework serde_json by optimizing error handling, utilizing the memchr crate, and implementing a single-pass algorithm, leading to a successful contribution.

Link Icon 1 comments
By @dang - 4 months
Related:

The Treacherous Optimization (2006) - https://news.ycombinator.com/item?id=21533301 - Nov 2019 (7 comments)