Skip to content

Commit

Permalink
Reduce memory usage in ValueStores by decreasing the number of kept i…
Browse files Browse the repository at this point in the history
…tems
  • Loading branch information
sebastian-peter committed Nov 14, 2022
1 parent 50a3a78 commit 5afbcaf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/scala/edu/ie3/simona/agent/ValueStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ object ValueStore {
): ValueStore[D] = {
val updatedStore = valueStore.store + (tick -> newEntry)

// always keep at least 3 entries
val minKeep = 3

valueStore.copy(
store = if (updatedStore.size > 5) { // always keep at least 5 entries
store = if (updatedStore.size > minKeep) {
val (rest, keep) =
updatedStore.keySet.to(SortedSet).splitAt(updatedStore.size - 5)
updatedStore.keySet.to(SortedSet).splitAt(updatedStore.size - minKeep)
val restPruned = rest.filter(_ > tick - valueStore.maxTickSpan)

val allTicks = restPruned ++ keep
Expand Down

0 comments on commit 5afbcaf

Please sign in to comment.