diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-06-09 11:52:12 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-06-09 11:52:12 +0200 |
| commit | 5dc9ddf3dad048984ba8b60f6a375d0c5d2ef731 (patch) | |
| tree | b87db8f895920dc178749ed84ed94b40cd508db6 | |
| parent | d146814bbbb86bfcb19ccb94250424703e9179e5 (diff) | |
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.
| -rw-r--r-- | opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt | 3 |
1 files changed, 2 insertions, 1 deletions
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<SimTraceFragment>): 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) |
