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

Easy way to delay & cache computed atom fields #6134

Closed
4 tasks done
JaroslavTulach opened this issue Mar 29, 2023 · 1 comment · Fixed by #6151
Closed
4 tasks done

Easy way to delay & cache computed atom fields #6134

JaroslavTulach opened this issue Mar 29, 2023 · 1 comment · Fixed by #6151
Assignees
Milestone

Comments

@JaroslavTulach
Copy link
Member

JaroslavTulach commented Mar 29, 2023

#6073 as well as #5085 are in need of efficient, properly implemented lazy atom fields. The engine is in the best position to deliver it. The alternative is to create a Lazy type in the libraries, but that's a hacky and ugly solution. There should be no Lazy type in the libraries, but the support shall come from the engine:

  • Provide metadata for widgets lazily #5085
  • we have a prototype that shows how it all can be done
  • the API will be simpler - just ~ in front of the atom field
  • the access to the field will be transparent - no difference between lazy/cached/eager field
  • the performance will be better if this is implemented in the engine
  • we'll use less memory, if this is done in the engine as we eliminate delegation once the field is materialized/cached

Library guys would be delighted - #6073 (comment) - to get " a more efficient engine solution - I will be really happy to have it replaced. The benefits sound cool."

Initial investigation tried to evaluate following program:

from Standard.Base import IO

type Lazy
    Value ~x ~y

    say self w = "Hello " + w.to_text

    meaning self = 
        IO.println "Computing meaning"
        v = self.x * self.y
        IO.println "Computed meaning"

main =
    compute_x =
        IO.println "Computing x"
        v = 6
        IO.println "Computing x done"
        v

    compute_y =
        IO.println "Computing y"
        v = 7
        IO.println "Computing y done"
        v

    IO.println "Start"
    l = Lazy.Value compute_x compute_y
    IO.println "Lazy value ready"
    IO.println <| l.say "Světe!"
    IO.println l.meaning
    IO.println <| l.say "Again!"
    IO.println l.meaning

to my biggest surprise it:

  • already compiles - e.g. ~ is acceptable value for constructor arguments
  • it delays the computation of ~x and ~y fields already
  • however it computes the fields again and again whenever they are accessed

E.g. what we need to do is to make sure each such ~ field is computed just once.

Tasks:

  • Use the prototype to store lazy values in Atom but obtain them like normal values
  • Modify the IR phases to allow ~ in Atom constructors
  • Verify no non-lazy Atom benchmarks are affected by this change
  • Create benchmark for Atoms with "lazy values" - it shall show there is some overhead of using laziness compared to strict Atom values
@JaroslavTulach JaroslavTulach added this to the Beta Release milestone Mar 29, 2023
@JaroslavTulach JaroslavTulach self-assigned this Mar 29, 2023
@JaroslavTulach JaroslavTulach moved this from ❓New to 📤 Backlog in Issues Board Mar 29, 2023
@JaroslavTulach JaroslavTulach linked a pull request Mar 30, 2023 that will close this issue
3 tasks
@jdunkerley jdunkerley moved this from 📤 Backlog to 🔧 Implementation in Issues Board Apr 4, 2023
@mergify mergify bot closed this as completed in #6151 Apr 5, 2023
mergify bot pushed a commit that referenced this issue Apr 5, 2023
Implements #6134.

# Important Notes
One can define lazy atom fields as:
```haskell
type Lazy
Value ~x ~y
```
the evaluation of the `x` and `y` fields is then delayed until they are needed. The evaluation happens once. Then the computed value is kept in the atom for further use.
@github-project-automation github-project-automation bot moved this from 🔧 Implementation to 🟢 Accepted in Issues Board Apr 5, 2023
@enso-bot
Copy link

enso-bot bot commented Apr 6, 2023

Jaroslav Tulach reports a new STANDUP for yesterday (2023-04-05):

Progress: - lazy atom fields integrated: #6151

Next Day: Consolidate Array & Vector

GitHub
Pull Request Description As per design, IOContexts controlled via type signatures are going away. They are replaced by explicit Context.if_enabled runtime checks that will be added to particular me...

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

Successfully merging a pull request may close this issue.

1 participant