Implement `fast_send`, reducing memory allocations
Whenever an actor calls `send(dest, v1, v2, ...)`, we previously allocated a `mailbox_element` and a `message` object. The `fast_send` optimization joins both objects into a single one using `pair_storage`: ``` pair_storage<mailbox_element, tuple_vals<Ts...>>: /-----------------------------------------------\ | | | /------------\ | | | | intrusive_ptr | intrusive_ptr v v | | +------------+-------------------+---------------------+ | refcount | mailbox_element | tuple_vals<Ts...> | +------------+-------------------+---------------------+ ^ ^ | | unique_ptr<mailbox_element, | detail::disposer> | | | intrusive_ptr<message_data> ``` Since each element in `pair_storage` lives inside a `union`, it is safe to simply call the destructor for each element in `request_deletion`. This is done by extending both types and override `request_deletion` accordingly (see `detail::embedded`). The only additional safety measure we need to take is to make sure to swap the `intrusive_ptr` out of each element *before* calling the destructor. This way, the destruct is guaranteed to be done before we attempt to release the storage.
Showing
Please register or sign in to comment