1. 12
  1.  

  2. 2

    A colleague of mine basically wrote a small research paper on how to do this with pointer reversal: Efficient Deconstruction with Typed Pointer Reversal, Guillaume Munch-Maccagnoni, 2019. Example Rust code in the case of binary trees is available at https://gitlab.com/gadmm/efficient-drops-demo/blob/master/abtree.rs. But the code is complex and hard to read if you don’t already know of the idea behind it – it is the result of a program transformation.

    1. 1

      Neat post. Thanks. Does rust drop in the same thread? With the mention of the allocation being unwanted I’m wondering if having it not block on destruction would help (or even be possible).

      1. 2

        By default, yes.

        It’s possible to write destructors that move the value to a different thread to be dropped. And even wrapper objects that let you use their contents as normal but move them to a different thread to be dropped.

        You’re adding overhead if you do this though, because moving data between cpu caches isn’t free.

        1. 1

          That makes sense. Thanks!