xtra icon indicating copy to clipboard operation
xtra copied to clipboard

Allocate queues in channel according to capacity

Open thomaseizinger opened this issue 3 years ago • 8 comments

In case the user passes a capacity, we know how many elements we will be storing in those queues. We can initialise them directly with this capacity which avoids growing those buffers on demand.

thomaseizinger avatar Aug 07 '22 08:08 thomaseizinger

Hm, I would actually tend to disagree with this change. This adds a fixed cost of 8 * capacity bytes per each type of mailbox, even if you don't use them. I intentionally left them as Vec::new as that doesn't allocate until use.

Restioson avatar Aug 10 '22 12:08 Restioson

Hm, I would actually tend to disagree with this change. This adds a fixed cost of 8 * capacity bytes per each type of mailbox, even if you don't use them. I intentionally left them as Vec::new as that doesn't allocate until use.

On the other hand, with this change we'd have a much more predictable memory footprint as it wouldn't change during operation.

I am not sure what is better?

thomaseizinger avatar Aug 10 '22 14:08 thomaseizinger

If a user really operates on constrained hardware or wants to preserve memory, they could set capacity to 0 right?

thomaseizinger avatar Aug 11 '22 06:08 thomaseizinger

If a user really operates on constrained hardware or wants to preserve memory, they could set capacity to 0 right?

I want to add a test that this actually works! Seems like an important enough case to cover.

thomaseizinger avatar Aug 11 '22 06:08 thomaseizinger

If they set capacity to zero that'd affect the default priority queue too, though

Restioson avatar Aug 11 '22 08:08 Restioson

If they set capacity to zero that'd affect the default priority queue too, though

And? It effectively means that split_receiver is useless because you can't queue the message so SendFuture will yield until the actor is ready to process the message.

But other than that, send will block the current task until the message is processed, same as before.

Am I missing something?

thomaseizinger avatar Aug 11 '22 10:08 thomaseizinger

Ideally, the user shouldn't have to choose between getting to use split_receiver and not allocating extra capacity for a channel that is never used. In the spirit of Rust's zero-cost abstractions and pay-for-what-you-use, I'd like the extra channels to add as little overhead as possible if you don't use them.

Restioson avatar Aug 12 '22 08:08 Restioson

It's also worth mentioning that the ordering behaviour might not work as expected with a rendezvous channel, but I'm not 100% sure of this

Restioson avatar Aug 12 '22 08:08 Restioson

Ideally, the user shouldn't have to choose between getting to use split_receiver and not allocating extra capacity for a channel that is never used. In the spirit of Rust's zero-cost abstractions and pay-for-what-you-use, I'd like the extra channels to add as little overhead as possible if you don't use them.

Hmm, I see where you are going with this. I think one could still argue that users should know whether they are using split_receiver and will thus pay the memory cost anyway so it doesn't matter whether they pay it on startup or during runtime.

thomaseizinger avatar Aug 16 '22 13:08 thomaseizinger