Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ScheduledTask to a struct to reduce allocations for scheduling #2010

Merged

Commits on Dec 14, 2021

  1. Convert ScheduledTask to a struct

    ### Motivation:
    
    In my previous PR apple#2009, I added baseline performance and allocation tests around `scheduleTask` and `execute`. After analysing, the various allocations that happen when scheduling a task there were only a few that could be optimized away potentially.
    
    ### Modifications:
    
    This PR converts the `ScheduledTask` class to a struct which will reduce the number of allocations for scheduling tasks by 1. The only thing that needs to be worked around when converting to a struct is giving it an identity so that we can implement `Equatable` conformance properly. I explored two options. First, using an `ObjectIdentifier` passed to the init. Second, using an atomic counter per EventLoop. I went with the latter since the former requires an additional allocation in the case of calling `execute`
    
    ### Result:
    
    `scheduleTask` and `execute` require one less allocation
    FranzBusch committed Dec 14, 2021
    Configuration menu
    Copy the full SHA
    584c6aa View commit details
    Browse the repository at this point in the history