Commit 3a84ff3
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- library/src/scala/collection
- immutable
2 files changed
+249
-212
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1372 | 1372 | | |
1373 | 1373 | | |
1374 | 1374 | | |
1375 | | - | |
| 1375 | + | |
1376 | 1376 | | |
1377 | 1377 | | |
1378 | 1378 | | |
| |||
0 commit comments