You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code throws a stack overflow on the last line:
varm:Map[Int, Double] =Map.empty
(1 until 10000).foreach{i =>
m = m.mapValues{x => x}
}
m.isEmpty
m.toList
Even if the map is empty, the repeated wrapping of MappedValues causes a stack overflow when the map is finally traversed (and leaks memory up until then). This can happen far away from the map's creation and is very hard to track down. This just caught us in production, essentially bringing down one of our live deployments.
This is related to #4776
but is an example of a runtime error, not just a design issue.
The text was updated successfully, but these errors were encountered:
@retronym said:
I would argue that this is really the same bug (albeit from a different perspective) as #4776: had you been aware that the operation was a view, you might have had a better chance at reasoning that it would be stack-unsafe to chain a large number of transformations.
Note that we've got a high performance map (restricted to non-primitive keys) in Scala 2.11 called AnyRefMap that includes a strict operation mapValuesNow. This wasn't lifted into the interface for Map, though.
The following code throws a stack overflow on the last line:
Even if the map is empty, the repeated wrapping of MappedValues causes a stack overflow when the map is finally traversed (and leaks memory up until then). This can happen far away from the map's creation and is very hard to track down. This just caught us in production, essentially bringing down one of our live deployments.
This is related to #4776
but is an example of a runtime error, not just a design issue.
The text was updated successfully, but these errors were encountered: