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-8742] Terrible performance with Range iteration in -Onone #51251

Open
airspeedswift opened this issue Sep 13, 2018 · 3 comments
Open

[SR-8742] Terrible performance with Range iteration in -Onone #51251

airspeedswift opened this issue Sep 13, 2018 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. performance standard library Area: Standard library umbrella

Comments

@airspeedswift
Copy link
Member

Previous ID SR-8742
Radar rdar://problem/69540062
Original Reporter @airspeedswift
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 2
Component/s Standard Library
Labels Bug, Performance
Assignee None
Priority Medium

md5: 47d7f9a85a07807d0d5ec5f2219800b6

relates to:

Issue Description:

In this PR: #16099

a benchmark was added to test Sequence.count(where: ) using Range:

public func run_CountAlgoRange(_ N: Int) {
  for _ in 1...N {
    CheckResults((0..<10_000_000).count(where: \{ $0 & 65535 == 0 }) == 153)
  }
}

This turned out to have really bad performance characteristics on -Onone, so the benchmark was changed to use Array instead. We should investigate why.

@troughton
Copy link
Contributor

Just to help prioritise this issue: we're seeing awful debug performance in our app due to this issue. I would argue that range iteration ought to compile to the same optimised code for both `-Onone` and `-O`, but instead large amounts of times are spent navigating protocol conformances and even making allocations.

For example, something like:

@inline(never)
func doSomething(_ x: Int) { print(x) }

func processNumbers(upTo x: Int) {
    for i in 0..<x {
        doSomething(i)
    }
}

should produce the same result in `-Onone` and `-O` for the processNumbers function, but instead produces https://godbolt.org/z/ez6da3 as opposed to https://godbolt.org/z/d7Y5GY.

@belkadan
Copy link
Contributor

See also SR-7277: "-Onone should inline @inline(__always)"

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. performance standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

4 participants