pool icon indicating copy to clipboard operation
pool copied to clipboard

Reset on checkin

Open tsnoam opened this issue 5 years ago • 4 comments

On certain usage patterns it might be more suitable to reset the values of the encapsulated data during checkin (When Checkout::drop() is executed) instead of during checkout.

tsnoam avatar Mar 31 '19 07:03 tsnoam

Thanks for the proposal. Could you describe the use case that requires reset on check-in? Before adding two options, I would like to evaluate whether reset on check-in should just be the only behavior.

carllerche avatar Apr 02 '19 21:04 carllerche

The use case goes like this:

Thread 1:

A tight loop handling a massive stream of incoming data. The incoming data is stored on an object taken from the pool. Only a fraction of the incoming data is sent to an handler thread.

Handle Thread (1 or more):

Performs additional computation on the data. Once its done, the object is dropped (and returned to the pool).

Problem:

Resetting the object in the thread1 (i.e. during checkout) takes time and stalls the tight loop.

Suggested Solution:

Reset the object in the handler thread (i.e. during checkin).

tsnoam avatar Apr 03 '19 04:04 tsnoam

reset logic could also be handled outside of the crate... I wonder if pool should get rid of the Reset trait all together. wdyt?

carllerche avatar Apr 03 '19 19:04 carllerche

Actually, I find the Reset logic as a really important feature of this library. It saves a lot of boilerplate code and more importantly avoids "accidents" where the developer forgets to explicitly call reset before a Checkout object is dropped.

tsnoam avatar Apr 04 '19 11:04 tsnoam