On 2025-09-05 at 22:39:12, Junio C Hamano wrote: > Junio C Hamano <gitster@xxxxxxxxx> writes: > > > ... Interestingly, disassembly I saw looked a lot more > > optimized than the C variant compiled with clang-19 -O2. > > That was a false alarm. With right compilation option passed, C > version of decode_varint() compiled to identical assembly as what > rustc/llvm produced. That's not unexpected, I'd say, especially since the code is very similar and uses very similar data structures, including pointers. However, as we adopt Rust more in the future, we may see some performance optimizations because Rust allows making more guarantees about data. For instance, the C compiler must deal with the fact that you can cast a const pointer to a non-const pointer, but Rust does not allow you cast or transmute an immutable slice to a mutable one or access it mutably at the same time, so the compiler can then assume that the data will not be modified, including by another thread, and optimize accordingly. -- brian m. carlson (they/them) Toronto, Ontario, CA
Attachment:
signature.asc
Description: PGP signature