Price-Checking Zerocopy's Zero Cost Abstractions

15 points by itamarst


robinhundt

This is really cool! Check out the docs of e.g. the ref_from_prefix method with a neat table showing what is benchmarked, what the assembly is and even a machine code analysis output (TIL that this exists, looks super helpful for optimizing and understanding performance of perf critical code).

The implementation of this is also neat. There are a bunch of benchmarks and expected outputs in the benches directory. The tests/codegen.rs file does snapshot testing of these benchmarks and the expected output with cargo-show-asm. The codegen test is then run in CI, to check for regressions. For the html tables, they wrote some somewhat cursed looking macros that expand to the nice html tabs with the content provided by the files in the benches directory.

All in all, really cool stuff! So far I have mostly used bytemuck for safe transmutes, but I'll definitely give zerocopy a closer look.