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

Deque.Iterator is slower than IndexingIterator #239

Open
2 tasks done
lorentey opened this issue Nov 10, 2022 · 0 comments
Open
2 tasks done

Deque.Iterator is slower than IndexingIterator #239

lorentey opened this issue Nov 10, 2022 · 0 comments
Labels
bug Something isn't working Deque The double-ended queue type

Comments

@lorentey
Copy link
Member

Deque implements a custom iterator that's supposed to be faster than just going through integer indices, but in actual benchmarks it turns out be slower. Either fix it to be faster, or if that cannot be done, just revert to the standard IndexingIterator.

Information

  • Package version: release/1.1
  • Platform version: macOS 13
  • Swift version: Swift 5.7

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • I've searched for existing GitHub issues.

Steps to Reproduce

Run the upcoming Deque benchmarks, and look at the results.

    self.add(
      title: "Deque<Int> sequential iteration (contiguous, iterator)",
      input: [Int].self
    ) { input in
      let deque = Deque(input)
      return { timer in
        for i in deque {
          blackHole(i)
        }
      }
    }

    self.add(
      title: "Deque<Int> sequential iteration (discontiguous, iterator)",
      input: [Int].self
    ) { input in
      let deque = Deque(discontiguous: input)
      return { timer in
        for i in deque {
          blackHole(i)
        }
      }
    }

    self.add(
      title: "Deque<Int> sequential iteration (contiguous, indices)",
      input: [Int].self
    ) { input in
      let deque = Deque(input)
      return { timer in
        for i in deque.indices {
          blackHole(deque[i])
        }
      }
    }

    self.add(
      title: "Deque<Int> sequential iteration (discontiguous, indices)",
      input: [Int].self
    ) { input in
      let deque = Deque(discontiguous: input)
      return { timer in
        for i in deque.indices {
          blackHole(deque[i])
        }
      }
    }

Expected behavior

I expected Deque.Iterator to be at least slightly faster than simply indexing from 0 to count.

Actual behavior

02 iteration

@lorentey lorentey added bug Something isn't working Deque The double-ended queue type labels Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Deque The double-ended queue type
Projects
None yet
Development

No branches or pull requests

1 participant