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

[SR-2023] Frequency of callbacks on Swift 3 DispatchSource timer event handlers is limited #44632

Closed
swift-ci opened this issue Jul 8, 2016 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SDKOverlay

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 8, 2016

Previous ID SR-2023
Radar None
Original Reporter brett (JIRA User)
Type Bug
Status Closed
Resolution Invalid

Attachment: Download

Environment

Xcode 8 beta 2 (8S162m) / Swift 3

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, SDKOverlay
Assignee brett (JIRA)
Priority Medium

md5: 399932a2429f24cdabecfc676c3870ac

Issue Description:

The frequency of DispatchSource.timer event handler callbacks is being limited in Swift 3. For example, with a scheduled interval of 1.0/60.0, the eventHandler set to the dispatch timer is only called roughly 12 times a second instead of the expected 60 times.

This behavior is (coincidentally or not) similar to a bug concerning NSTimer and CADisplayLink that I filed during Xcode 8b1 (radar #26833801 – fixed in beta 2), except this behavior occurs both on device and Simulator, and does not occur with Swift 2.3 or Objective-C. This may point to something specific within the GCD implementation in Swift 3.

I've attached two test case projects; one is Swift 3 (exhibits the bug), and one is Swift 2.3 (callbacks are as expected).

@belkadan
Copy link
Contributor

belkadan commented Jul 8, 2016

cc phabouzit (JIRA User)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 8, 2016

Comment by Pierre Habouzit (JIRA)

{{
dispatchTimer.scheduleRepeating(deadline: DispatchTime.now(), interval: (1.0/60.0), leeway: DispatchTimeInterval.milliseconds(1))
}}

calls into

{{
public func scheduleRepeating(deadline: DispatchTime, interval: Double, leeway: DispatchTimeInterval = .nanoseconds(0)) {
__dispatch_source_set_timer(self as! DispatchSource, deadline.rawValue, UInt64(interval * Double(NSEC_PER_SEC)), UInt64(leeway.rawValue))
}
}}

which looks completely correct to me.

so investigating

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 8, 2016

Comment by Pierre Habouzit (JIRA)

When I trace in the debugger dispatch_source_set_timer() is called with the right interval value, but clearly the code runs at 6Hz and not 60

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 8, 2016

Comment by Pierre Habouzit (JIRA)

This is a project bug:

DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes(rawValue: DispatchQueueAttributes.qosUserInteractive.rawValue))

is using rawValues that aren't compatible. GlobalAttributes are NOT DIspatchQueueAttributes.

DispatchQueue.global(attributes: [ .qosUserInteractive ]))

will fix it.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 8, 2016

Comment by Daniel A. Steffen (JIRA)

I filed
<rdar://problem/27236887> DispatchQueue.GlobalAttributes is confusing
to track improving this aspect of the new API (the argument to global() doesn't need to be an OptionSet at all, or be called an attribute)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 8, 2016

Comment by Brett Walker (JIRA)

Thanks for catching my mistake, Pierre. Mea culpa. I do agree with Daniel that the new dispatch timer API is quite a mouthful and could be improved. The use of rawValue here doesn't seem to be very Swifty as it encourages the kind of mistake I just made, instead of enforcing stricter type checking.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SDKOverlay
Projects
None yet
Development

No branches or pull requests

2 participants