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

scanLeft (and right) for TraversableViewLike is very ineffective #9902

Closed
scabug opened this issue Aug 23, 2016 · 6 comments
Closed

scanLeft (and right) for TraversableViewLike is very ineffective #9902

scabug opened this issue Aug 23, 2016 · 6 comments

Comments

@scabug
Copy link

scabug commented Aug 23, 2016

Now implementation of scanLeft for TraversableViewLike is this

override def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That =
    newForced(thisSeq.scanLeft(z)(op)).asInstanceOf[That]

It goes to calculate all the collection when we call some method of the "view". But it is not the way, because we may want to take only a part of collection with "takeWhile" or "find" or "indexWhere". It should be implemented like "foldLeft" for "views"—using "foreach" call. But better potential implementations of many view's methods are with "iterator". And it should not be forced—it is a "view" after all. All the operations should be lazy.

Now it is 100 times slower than it should be.

Probably, they are another view methods, these have non-lazy implementations.

@scabug
Copy link
Author

scabug commented Aug 23, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9902?orig=1
Reporter: Lex (lex-kravetski)
Affected Versions: 2.11.8

@scabug
Copy link
Author

scabug commented Aug 23, 2016

@SethTisue said:
über-ticket is #4332

@scabug
Copy link
Author

scabug commented Aug 23, 2016

@scabug
Copy link
Author

scabug commented Aug 24, 2016

@szeiger said:
These kinds of problems should go away if we can adopt a design similar to Martin's latest strawman proposals for 2.13. In these designs views are essentially reified operations on Iterators plus an underlying collection.

@SethTisue
Copy link
Member

closing since everything is changing in the 2.13 collections. someone with an interest in this ticket could verify whether it still exists in scala/collection-strawman now, or wait for Scala 2.13.0-M4 to land (when collection-strawman will be merged) and check it then.

@SethTisue SethTisue removed this from the Backlog milestone Mar 1, 2018
@NthPortal
Copy link

This is fixed in strawman.

Traversible is deprecated in strawman, and Iterable should be used instead. TraversibleViewLike no longer exists; its closest replacement, IterableOps.scanLeft, is implemented lazily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants