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

[regression, performance] iterator makes deep copy for openArray, can cause major slowdowns #13726

Closed
timotheecour opened this issue Mar 22, 2020 · 1 comment

Comments

@timotheecour
Copy link
Member

timotheecour commented Mar 22, 2020

the recently merged #13712 causes a performance regression. Inline iterators are intended for speed, we shouldn't introduce un-necessary copies. /cc @krux02

Example

block:
  let n = 10_000_0000
  var s = newSeq[int](n)
  proc p2(): var seq[int] = s

  iterator ip1(v: openArray[int]): auto =
    yield v[0]
    yield v[^1]

  import times
  let t = cpuTime()
  for i in 0..<100:
    for x in ip1(p2()):
      doAssert x != -1
  echo cpuTime() - t

Current Output

12.171379 # seconds

Expected Output

7.000000000034756e-06 # seconds, before that PR, eg with nim 1.0.6

Possible Solution

EDIT: the revert has been done in #13728

Additional Information

@Araq Araq closed this as completed Mar 23, 2020
@krux02
Copy link
Contributor

krux02 commented Mar 23, 2020

# arrays will deep copy here (pretty bad).

Well I even put a comment about this performance problem in the code. So this is nothing new. I would have been nicer if this would have been complained ahead of time. But I guess performance is ranked higher than correctness in this particular case.

@krux02 krux02 mentioned this issue Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants