rluiten/elm-date-extra

Huge RAM consumption when calling Date.Extra.Utils.dayList with a negative integer.

Closed this issue · 3 comments

I just discovered this unusual behavior to the dayList function which is defined as:

dayList : Int -> Date -> List Date

Calling Date.Extra.Utils.dayList -2 someDate, creates a huge immediate bump into RAM consumption. Then the hole app gets frozen.

For positive numbers it works as expected. But I by mistake was getting a negative integer by calling:
Date.Extra.Duration.diffDays startDate endDate

That is very funny and a good find thanks.
It is creating a massive list by subtracting 1 from your -2 until it reaches Zero :).

I hope to get to this in next day or so.
Do you have an opinion for negative counts I propose making it return a list of days going back in time instead of forward by the given amount of days.

from @tolgapaksoy in slack channel :

"i guess it’s because the recursion check is only done with == 0, and not <= 0:
https://github.com/rluiten/elm-date-extra/blob/8.5.0/src/Date/Extra/Utils.elm#L52 ."

Yeah, i rely like this library. Thanks so much for building it 👍

Fixed in 8.5.1.
Thanks.