from Hacker News

The Rust Performance Book (2020)

by cwaffles on 4/20/23, 2:32 PM with 27 comments

  • by asicsp on 4/20/23, 3:00 PM

  • by kibwen on 4/20/23, 2:56 PM

    Note that nnethercote is probably the world's foremost expert on Rust performance (in addition to being the maintainer of Valgrind). See also his long-running blog series where he discusses his efforts to improve the performance of the Rust compiler itself: https://nnethercote.github.io/2023/03/24/how-to-speed-up-the...
  • by cmrdporcupine on 4/20/23, 4:06 PM

    One thing I've been curious about -- but not enough to actually run through the disassembly yet -- is the performance of Rust matching on enums vs C/C++ switch statement -- in particular in e.g. a 'bytecode' interpreter loop.

    C compilers do a pretty good job of optimizing these into something pretty efficient, and I imagine it helps that the size of the case values is constant, and it can be turned by the compiler into either a jump table lookup or an unrolled jmp depending on size, etc.

    Rust enums, in contrast, can be variable sized at match time. And the elements can be nested a few levels deep. The obvious way to write an opcode execution loop in Rust -- a pattern match over an enum of opcodes -- I'm curious if this can be made to perform as well as in C/C++.

    (I've been writing a virtual machine interpreter loop and so have a modest interest in seeing how this kind of thing, though I'm not optimizing for performance yet, so)

    Don't see any explicit mention of this in this document.

  • by cwaffles on 4/20/23, 2:33 PM

    There's a good discussion on minimizing heap allocations: https://nnethercote.github.io/perf-book/heap-allocations.htm...
  • by peoplearepeople on 4/20/23, 3:55 PM

    Is there a printed version?