Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groupsOf and friends can exceed maximum call stack size #164

Open
jmbromley opened this issue May 13, 2022 · 1 comment
Open

groupsOf and friends can exceed maximum call stack size #164

jmbromley opened this issue May 13, 2022 · 1 comment

Comments

@jmbromley
Copy link

groupsOf and friends are not truly tail recursive because they use List.take from elm/core. But the core implementation of List.take only switches to a (slightly slower) tail recursive implementation after it has processed 1000 elements. This means that if groupsOf has a large number of recursions then it can build up an excessive call stack from repeated calls to List.take (each of which could have a stack of up to 1000 calls).

A realword of example of this causing "maximum call stack size exceeded" errors is billstclair/elm-crypto-string#10.

jmbromley added a commit to jmbromley/list-extra that referenced this issue May 13, 2022
@Chadtech
Copy link
Collaborator

This is really interesting. I appreciate your code too. In your PR you ask if this is too much of a corner case to worry about. Yeah, it might be. I am always torn because, it is great to document these trade offs and discover these optimizations for people to find. On the other hand its not good to include them as general or "go to" functions for people to use.

I wonder if we should make a new module called like List.Extra.TailRec for these functions?

I guess before we would even want to look into that we should measure the exact performance trade off for full stack safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants