Skip to content

Fix the capacity of poolable#1

Merged
dignifiedquire merged 2 commits intoasync-email:masterfrom
flub:flub/fix-poolable-capacity
Jul 29, 2020
Merged

Fix the capacity of poolable#1
dignifiedquire merged 2 commits intoasync-email:masterfrom
flub:flub/fix-poolable-capacity

Conversation

@flub
Copy link
Member

@flub flub commented Jul 27, 2020

I've tested this with the test suites of async-h1, async-imap, deltachat-rust-core and with my imapsyncer tool. With this fix the latter is able to reliably download and synchronise 260k emails, without this fix the stream always gets stuck* at some point.

  • depending on my local changes to async-imap "stuck" varies from an infinite loop to erroring out. That's for another PR.

commit message:

A vector can allocate more space than the current number of elements,
this allows it to cheaply grow the elements. This is what
vec.capacity() returns. vec.len() returns the actual number of items
in use, this is also the number of items you will get when slicing
with e.g. vec[..]. This latter matters since this is how the block is
meant to be used: a lot of consumers silce the block. Hence vec.len()
gives the actual capacity of the block. This is also reflected with
how the block (re)allocates capacity: vec.resize() changes the Vec's
len with no guarantees how it affects the Vec capacity.

A vector can allocate more space than the current number of elements,
this allows it to cheaply grow the elements.  This is what
vec.capacity() returns.  vec.len() returns the actual number of items
in use, this is also the number of items you will get when slicing
with e.g. vec[..].  This latter matters since this is how the block is
meant to be used: a lot of consumers silce the block.  Hence vec.len()
gives the actual capacity of the block.  This is also reflected with
how the block (re)allocates capacity: vec.resize() changes the Vec's
len with no guarantees how it affects the Vec capacity.
@link2xt
Copy link
Collaborator

link2xt commented Jul 27, 2020

Maybe add this explanation to the code comment too?

@dignifiedquire
Copy link
Member

can you update the HashMap impl as well please?

It seems the hashmap capacity is, similarly to Vec, not exactly
controllable and we can not always guarantee len == capacity.  Again
similarly when Block::size() returns a given lenght you expect to be
able to index to this length.
@flub flub changed the title Fix the capacity of poolable for Vec<T> Fix the capacity of poolable Jul 29, 2020
@dignifiedquire dignifiedquire merged commit 60f4ce6 into async-email:master Jul 29, 2020
@flub flub deleted the flub/fix-poolable-capacity branch July 29, 2020 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants