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

Improve user experience for big List.range calls #7032

Open
Anton-4 opened this issue Aug 27, 2024 · 1 comment
Open

Improve user experience for big List.range calls #7032

Anton-4 opened this issue Aug 27, 2024 · 1 comment

Comments

@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 27, 2024

Relocated from roc-lang/examples#199. issue reported by @alexpyattaev:

The example below segfaults on roc --version:
roc nightly pre-release, built from commit faeea52 on Fr 23 Aug 2024 09:01:42 UTC
There are no compilation errors of any kind.

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.14.0/dC5ceT962N_4jmoyoffVdphJ_4GlW3YMhAPyGPr-nU0.tar.br" }

import pf.Stdout
import pf.Task

loop = \i, max ->
    if i < max then
        i + loop (i + 1) max
    else
        i

main =
    x = 1000 * 1000 * 1000
    z = loop 0 x
    # z = List.range {start: At 0, end: Before x} |> List.walk 0 Num.add
    Stdout.line! "Hello, World! $(Num.toStr z)"

The commented out line was the other attempt at computing the same sum, which resulted in OOM kill of the process as it tried to allocate 1 billion element long List. Not sure why, but it was clearly unnecessary here.

changing the loop impl to this makes the thing work correctly, but it is ugly as sin and not obvious for the user to figure out what the problem is.

loop = \sum, i, max ->
    if i < max then
        loop (sum + i) (i + 1) max
    else
        sum
@Anton-4 Anton-4 changed the title Improve user experience for large allocations Improve user experience for big List.range calls Aug 27, 2024
@Anton-4
Copy link
Collaborator Author

Anton-4 commented Aug 27, 2024

Discussion of issue

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

1 participant