Unofficial Hacker News companion — get notified on comment replies, and more.

Show HN: misa77 – Up to 3x faster decompression than zstd, with better ratios (opens external site)

248 points by nonadhocproblem 15 hours ago github.com 81 comments (opens Hacker News) Vote (opens Hacker News)

View full thread · View on Hacker News

Comment thread (2)

  1. There's two parts that still use unsafe right now:

    1. The hash table for finding matches. This is incredibly important for compression performance, and every lookup has the form TABLE[hash & mask]. The mask guarantees it is in-bounds, but Rust doesn't understand this unless you use a compile-time sized TABLE which is a bunch of duplicate codegen. So I made an unsafe wrapper for it that gets initialized with a capacity and a known-good mask. This is really uncontroversial.

    2. The core LZ decompression loop. This is pretty much a worst-case scenario where every single instruction added has a 10-20% performance impact. The LZ loop is a constant chain of the form "copy n bytes from offset i", needs constant bounds checks. We actually do those bounds checks, but amortized (we check e.g. once every 8 iterations that our buffer is large enough for the next 8 iterations, even in the worst case), which due to the dynamic nature of offsets here is not something the compiler understands.

    Replies (1)
    1. Have you considered using tools like Verus [0] or Aeneas [1] to prove some safety properties? Point 1 feels especially doable in Verus.

      [0]: https://verus-lang.github.io/verus/guide/ [1]: https://aeneasverif.github.io