The Fastest, Safest PNG Decoder in the World

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • Scout APM - Truly a developer’s best friend
  • InfluxDB - Build time-series-based applications quickly and at scale.
  • talent.io - Download talent.io’s Tech Salary Report
  • SonarLint - Clean code begins in your IDE with SonarLint
  • wuffs

    Wrangling Untrusted File Formats Safely

    Wuffs touts its lack of memory allocation as a safety feature [0]. Rust could add a `#![forbid(alloc)]` declaration and achieve the same effect. I think this would be a good idea.

    Wuffs types are not parameterized with lifetimes, so they may contain references only to items with static lifetime. This means that Wuffs cannot implement linked lists, hash tables, or other common data structures. To support those structures, Wuffs will need to either add lifetime parameters and a borrow-checker (like Rust) or add reference counting (like Rust `Arc`, C++ `shared_ptr`, Golang, Java, etc).

    [0] https://github.com/google/wuffs/blob/v0.3.0-beta.1/doc/note/...

  • smhasher

    Hash function quality and speed tests (by rurban)

    Looks good, but has somewhat widely false claims:

    > SMHasher is a test and benchmark suite for a variety of hash function implementations. It can provide data for claims like “our new Foo hash function is faster than the widely used Bar, Baz and Qux hash functions”. However, when comparing Foo to CRC-32, be aware that a SIMD-accelerated CRC-32 implementation can be 47x faster than SMHasher’s simple CRC-32 implementation.

    In fact smhasher implements both, the slow soft crc32 he cites, and the fastest crc32_pclmul, which is not just 47x faster, but 5000x faster. Other than wuff's implementation of the crc32_pclmul variant.

    Compare https://github.com/rurban/smhasher/#smhasher

        crc32  392.10 vs crc32_pclmul 1972140.38 MiB/sec

  • Scout APM

    Truly a developer’s best friend. Scout APM is great for developers who want to find and fix performance issues in their applications. With Scout, we'll take care of the bugs so you can focus on building great things 🚀.

  • png-decoder

    A pure-Rust, no_std compatible PNG decoder

    I recently wrote a Rust PNG decoder mostly for use in no_std contexts, and it was motivated out of wanting to decode emoji for a font rasterizer.

    I didn't really put any effort into optimizing it yet, though it does use miniz_oxide and it decompresses the entire image at once instead of per-scanline.

    I'm curious if it is at all competitive with the Wuffs decoder, I'm guessing probably not because I haven't put any effort into using SIMD.

    https://github.com/bschwind/png-decoder

    But overall the implementation was pretty straightforward, I just read the RFC and wrote it out over a few weeks. One quirk of my library currently is it always returns an RGBA buffer, instead of potentially letting you save memory on a grayscale or RGB image.

  • ivory

    The Ivory EDSL

    Another tool along these lines is Galois' Ivory language https://ivorylang.org/ , a Haskell-embedded language for writing safe/reliable C.

  • stb

    stb single-file public domain libraries for C/C++

    The language itself is a little unreadable at first glance, but the idea of it is a very good one. sbt [1] is an amazing project for small embeddable toy programs, but using fuzzers rapidly shows how unsafe the code is, and the benchmarks in the original article show the extent of performance compromises made to make it work.

    It seems like this would be an interesting approach to a lot of security programming where it involves data structures, since those have typically been a source of issues. Having a memory-safe ASN.1 parser would be really nice, considering how much difficulty that has caused in the security space.

    With a lot of security programming there's a reliance on constant-time algorithms, which this may not be well-suited to, however.

    [1] https://github.com/nothings/stb

  • ableC

    Attribute grammar Based Language Extensions for C

    I work on (well, mostly near) an extensible C compiler, designed so extension authors can independently create extensions, and users can import them as easily as libraries: https://github.com/melt-umn/ableC/

    IMO this approach hasn't taken off because maintaining compatibility with C while adding safety (or really just about any property) means implementing your own sublanguage that can't arbitrarily call C functions while maintaining your safety properties. On the other hand, C being able to call into your sublanguage easier is a benefit versus jury-rigging Cargo into your build system (in the case of Rust).

    On the other hand, this approach works great for adding extensions that increase the expressive power of C with new abstractions, for example algebraic data types, C++-like templating, etc.

  • Halide

    a language for fast, portable data-parallel computation

  • InfluxDB

    Build time-series-based applications quickly and at scale.. InfluxDB is the Time Series Data Platform where developers build real-time applications for analytics, IoT and cloud-native services in less time with less code.

  • Compiler

    > I'm a big believer in technical continuity.

    So am I. D is designed to be an easy transition from C and C-With-Classes. For example, here is some code in C that was translated to D (it's part of the DMD compiler):

    C:

    https://github.com/DigitalMars/Compiler/blob/dmc-cxx/dm/src/...

    D:

    https://github.com/DigitalMars/Compiler/blob/master/dm/src/d...

    They look pretty much the same. The code generated is the same. In those repositories you can also see how I translated the C versions to D with plenty of examples.

    The biggest impediment is the C preprocessor. You wouldn't really want to carry that forward.

    After removing dependency on the C preprocessor, most of the work is global search/replacing things like `->` to `.`.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts