Should Store use a Deque instead of an Array?

Hi all,

I was checking out the Store implementation, and saw that the send(_:) method has a lot of append(_:) and removeFirst() calls on the synchronousActionsToSend and bufferedActions array properties. Recently, Swift Collections was launched, with one notable new collection being a Deque. Deques offer constant-time append(_:) and popFirst() operations (the graph shows performance for prepend(_:), but IIUC the same constant-time performance can be expected for these two methods too).

The performance benefits really start to kick in once the Deque grows to more than 64 elements, which AFAIU can be expected in a moderately complex app with a large amount of actions quickly being passed into the store (such as for an action fired by an Effect.timer, or an action connected to a scrollViewDidScroll(_:)).

I understand that the swift-collections library hasn't hit its 1.0 release yet, but I doubt Deques append(_:) and popFirst() API would change.

Would it make sense to replace those two Arrays with Deques?

I'd be happy to test it out myself – are there any standard performance tests I can turn to for TCA, with a large amount of effects fired?


What is "the Store implementation"? Can you include a link?

Sure! I edited the original post with the link too.

1 Like
Terms of Service

Privacy Policy

Cookie Policy