Do you mind elaborating on the parts of your rust design which are currently “unsafe”. I just want to better understand why these tradeoffs are being made and what the effects are.
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.
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.