Skip to content

[WIP] Rework of immutable.Queue to avoid copying data into the "in" list#8602

Closed
joshlemer wants to merge 4 commits intoscala:2.13.xfrom
joshlemer:queue-redo
Closed

[WIP] Rework of immutable.Queue to avoid copying data into the "in" list#8602
joshlemer wants to merge 4 commits intoscala:2.13.xfrom
joshlemer:queue-redo

Conversation

@joshlemer
Copy link
Contributor

@joshlemer joshlemer commented Dec 18, 2019

This is a reworking of the structure of Queue's in: List[A] to be now a List[A | Many[A]], which allows for enqueueAll operations to be performed in O(1) by simply setting

in = Many(that) :: this.in

When a rotation happens (when a dequeueing occurs which causes us to rotate the in list to the out list, at that point, the in list is flattened to construct the new out list.

The end result is that instead of copying the data twice (copying once into in and again to rotate into out), we only perform one copying of the data, at rotation-time. We avoid the equeueAll-time copying by appending prepending the collection itself as the first element of in.

An other more elaborated description was written here: #8565 (comment)

This is a very early version of this PR and it is definitely not ready for merging.

Also, this one is on pause until at least #8601 is through, since this code somewhat depends on that code to realize performance improvements, so benchmarks compared to the 2.13.x branch are underwhelming or even negative.

TODO

  • Run benchmarks to ensure that the expected speedups are indeed worth the complexity, and other operations on queues are not slowed down (by much)

  • Write more unit/prop tests for queues

  • Implement faster queue.apply(Int) implementation

  • Extract iterator class from queue

  • Make any necessary changes to Queue scaladocs and if applicable, scala-lang.org

@scala-jenkins scala-jenkins added this to the 2.13.2 milestone Dec 18, 2019
@joshlemer joshlemer changed the title Rework of immutable.Queue to avoid copying data into the "in" list [WIP] Rework of immutable.Queue to avoid copying data into the "in" list Dec 18, 2019
@diesalbla diesalbla added the library:collections PRs involving changes to the standard collection library label Dec 24, 2019
@SethTisue SethTisue modified the milestones: 2.13.2, 2.13.3 Feb 6, 2020
@SethTisue SethTisue modified the milestones: 2.13.3, 2.13.4 May 12, 2020
@SethTisue
Copy link
Member

@joshlemer interested in returning to this?

@dwijnand dwijnand modified the milestones: 2.13.4, 2.13.5 Oct 16, 2020
@dwijnand
Copy link
Member

dwijnand commented Dec 4, 2020

Closing for inactivity. @joshlemer feel free to open a ticket to save the idea + link to the WIP here.

@dwijnand dwijnand closed this Dec 4, 2020
@dwijnand dwijnand removed this from the 2.13.5 milestone Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

library:collections PRs involving changes to the standard collection library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants