Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Skinny Deferred #229

Merged
merged 6 commits into from
May 22, 2018
Merged

Skinny Deferred #229

merged 6 commits into from
May 22, 2018

Conversation

zwaldowski
Copy link
Contributor

@zwaldowski zwaldowski commented Apr 29, 2018

Deferred is meant to handle large parts of an app's asynchronous control flow, so its performance is critical. We've strived in the past to use the best constructs we have at our disposal to make this possible, like being early adopters of GCD in Swift. #213 revealed we can still do better! 😃

What's in this pull request?

By combining our waiters queue and the storage, Deferred (the type) can reach same-ballpark performance as GCD while maintaining the same invariants.

Per the performance tests, this PR features:

  • A 70% reduction in peak memory usage
  • A 35% speed improvement in simple operations
  • An 80% speed improvement in chained operations
  • Smaller call stacks when debugging upon handlers.

In summary: same great taste, less filling.

This representation allows Swift-side access to handlers, possibly allowing for #203.

TODO

  • What about code size? This PR gains about 30KB for Release under 4.1, which is livable, but not ideal for my OCD.

Testing

Largely no impact, but Deferred gains a specialization where Value: AnyObject that needs testing.

TODO

  • Needs duplicated tests to handle AnyObject specialization
  • Double-check other coverage implications

API Changes

No public API changes here, it's all under the hood.

@zwaldowski zwaldowski added the wip label Apr 29, 2018
@zwaldowski zwaldowski added this to the 4.0 milestone Apr 29, 2018
@zwaldowski zwaldowski force-pushed the zwaldowski/skinny-deferred branch 3 times, most recently from 6fed315 to cfc500f Compare April 30, 2018 05:36
extension Deferred: PromiseProtocol {
@discardableResult
public func fill(with value: Value) -> Bool {
return variant.awake(with: value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename store(_:).

@zwaldowski zwaldowski force-pushed the zwaldowski/skinny-deferred branch 2 times, most recently from 472e0f4 to 1cf1dcd Compare May 12, 2018 04:11
@zwaldowski zwaldowski force-pushed the zwaldowski/skinny-deferred branch 6 times, most recently from db38b45 to c04894a Compare May 18, 2018 05:29
@zwaldowski zwaldowski removed the wip label May 22, 2018
@zwaldowski zwaldowski merged commit 83cf62e into master May 22, 2018
@zwaldowski zwaldowski deleted the zwaldowski/skinny-deferred branch May 22, 2018 20:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant