Skip to content

Commit 3a84ff3

Browse files
committed
Reduce memory footprint of evaluated values in LazyList
The LazyList implementation uses two objects per evaluated value, a LazyList and one State instance. So the overhead for evaluated values is 2x compared to Stream. This PR reduces the overhead to one LazyList instance with two fields (head and tail) per evaluated value. Thread safety is implemented through checking the volatile `head` field and synchronizing on `this` for initialization. This is the equivalent to the previous implementation which uses a `lazy val`. Breaking changes: Serialization is not compatible. Non-evaluated (tails of) streams are serialized using plain object serialization. The internals are different and serialization is incompatible in both directions.
1 parent b2dcd69 commit 3a84ff3

File tree

2 files changed

+249
-212
lines changed

2 files changed

+249
-212
lines changed

library/src/scala/collection/IterableOnce.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
13721372
if (it.hasNext) {
13731373
jsb.append(it.next())
13741374
while (it.hasNext) {
1375-
jsb.append(sep)
1375+
if (sep.length != 0) jsb.append(sep)
13761376
jsb.append(it.next())
13771377
}
13781378
}

0 commit comments

Comments
 (0)