Grebennikov Roman / findify.io / @public_void_grv
Scalar 2018
twitter: @public_void_grv email: grv@dfdx.me
Large JVM heaps:
case class Pageview(id: String, time: Long)
case class Pageview(id: String, time: Long)
Pageview(id = "p123", time = 0L)
How much heap does Pageview use?
Object header | 12 |
String reference | 4 |
String object header | 12 |
String array reference | 4 |
String array header | 12 |
String char array size | 4 |
Char array | 4 or 8 |
millis | 8 |
case class ::[B](val head: B, var tl: List[B]) extends List[B] {
override def tail : List[B] = tl
override def isEmpty: Boolean = false
}
val pageviews = List.fill(1000000)(_ =>
Pageview(
id = Random.nextString(4),
time = Random.nextLong()
)
)
jamm: track real memory usage on HotSpot
class Pageview {
std::string id;
int64_t ts;
};
int main() {
std::cout << sizeof(Pageview);
}
Can it be achieved within JVM?
demo: packing pageviews
case class Easy(id: String, ts: Long)
case class Regular(id: String, easy: Easy)
case class Hardcore(id: String, other: List[Hardcore])
sealed trait Nightmare
case class Leaf(value: String) extends Nightmare
case class Node(left: Nightmare, right: Nightmare) extends Nightmare
Implement typeclasses for:
Benchmark listType Mode Cnt Score Error Units
filter Vector avgt 100 11291.284 ± 117.354 ns/op
filter List avgt 100 6801.318 ± 31.750 ns/op
filter PackedList avgt 100 14877.129 ± 470.324 ns/op
foreach Vector avgt 100 3462.084 ± 79.947 ns/op
foreach List avgt 100 3061.652 ± 30.891 ns/op
foreach PackedList avgt 100 9579.002 ± 80.827 ns/op
Benchmark mapType Mode Cnt Score Error Units
build1000 Map avgt 100 174976.058 ± 4784.830 ns/op
build1000 PackedMap avgt 100 324695.548 ± 3652.811 ns/op
lookupExisting Map avgt 100 48.297 ± 0.267 ns/op
lookupExisting PackedMap avgt 100 128.332 ± 1.251 ns/op
lookupNonExisting Map avgt 100 40.084 ± 0.808 ns/op
lookupNonExisting PackedMap avgt 100 25.322 ± 0.751 ns/op
Insults | 100 | 200 | 300 | 400 | 500 |
Holy war | 100 | 200 | 300 | 400 | 500 |
Algorithms | 100 | 200 | 300 | 400 | 500 |
Cargo cult | 100 | 200 | 300 | 400 | 500 |
Emotional burn-out | 100 | 200 | 300 | 400 | 500 |
Haskell | 100 | 200 | 300 | 400 | 500 |
a slide by @nikitonsky |