From 5dc9ddf3dad048984ba8b60f6a375d0c5d2ef731 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 9 Jun 2022 11:52:12 +0200 Subject: fix(sim/compute): Limit growth rate for trace construction This change fixes an issue where the `SimTrace.Builder` would quickly allocate too much memory when constructing a trace, due to doubling the array sizes each time. Instead, we use the approach used by `ArrayList`, where we increase the array size by 50% every step. --- .../src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'opendc-simulator') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt index 207e8579..6b820e5d 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt @@ -55,6 +55,7 @@ public class SimTrace( /** * Construct a [SimTrace] with the specified fragments. */ + @JvmStatic public fun ofFragments(fragments: List): SimTrace { val size = fragments.size val usageCol = DoubleArray(size) @@ -180,7 +181,7 @@ public class SimTrace( */ private fun grow() { val arraySize = usageCol.size - val newSize = arraySize * 2 + val newSize = arraySize + (arraySize shr 1) usageCol = usageCol.copyOf(newSize) timestampCol = timestampCol.copyOf(newSize) -- cgit v1.2.3