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

An additional type of Stream cons cell whose stream is passed by value might speed up some uses of streams #4698

Closed
scabug opened this issue Jun 15, 2011 · 2 comments

Comments

@scabug
Copy link

scabug commented Jun 15, 2011

I have an application that creates a Stream with Stream.iterate, but as it processes the items in the stream, it sometimes pushes new items onto the front of the stream. (The application uses +:, which didn't work as I expected, and for which I submitted #4697).

In the course of tracking down the problem, I created my own featherweight Stream implementation (attached), which contains only the Stream facilities I'm actually using.

In writing my Stream implementation, it occurred to me that when I'm pushing an item onto the front of an already-evaluated stream, it's probably not very efficient to wrap the stream in a thunk and then unwrap it again when I need it. Instead, I created a stream composed of two different kinds of Cons cells -- LazyCons takes a by-name tail, as in the standard implementation, but EagerCons takes a by-value tail (like a List cell), and is chosen in cases like +: where the tail is already evaluated.

If you run the timing test archontophoenix.stream.TimeStreams in the attached file, the numbers suggest that using EagerCons can save some time in cases like mine. Whether it saves enough time to be worth integrating something like this into the standard library is another question, but I thought I'd throw it out there.

@scabug
Copy link
Author

scabug commented Jun 15, 2011

Imported From: https://issues.scala-lang.org/browse/SUGGEST-2?orig=1
Reporter: archontophoenix
Attachments:

  • Stream.scala (created on Jun 15, 2011 3:06:12 AM UTC, 3373 bytes)

@scabug
Copy link
Author

scabug commented Jul 17, 2015

@SethTisue said:
Your input is appreciated, but I'm afraid we are no longer accepting "Suggestion" tickets on JIRA.

Available mechanisms for making suggestions include:

  • the Scala mailing lists
  • SIP (Scala Improvement Process) and SLIP (Scala Library Improvement Process)
  • a pull request on GitHub implementing the suggestion

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

1 participant