Skip to content

WIP remove MonadIO requirement#80

Open
DavidEichmann wants to merge 1 commit intojonascarpay:masterfrom
DavidEichmann:pure
Open

WIP remove MonadIO requirement#80
DavidEichmann wants to merge 1 commit intojonascarpay:masterfrom
DavidEichmann:pure

Conversation

@DavidEichmann
Copy link

This is intended to allow both pure and impure stores (and hence underlying monad) to be used under the hood. I think most stores can be made pure with little performance hit as updating the world record will be fast compared to updating the store itself (e.g. updating an IntMap). This should allow the whole world to be expressed as an immutable data type.

@DavidEichmann
Copy link
Author

@jonascarpay This is just a start! But maybe you can have a look at the changes to Core.hs and Stores.hs to see if I'm on the right track.

-- | Writes a component to the store. Returns @Just@ a new store if the store
-- has changed. If the store is mutable and only undergoes internal mutation,
-- then you can safely return @Nothing@
explSet :: s -> Int -> Elem s -> m (Maybe s)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized the Maybe is a premature optimization, here and in explDestroy. I may just drop it and and return m s. That should simplify some other changes.

@jonascarpay
Copy link
Owner

The crux of the issue for me is this:

I think most stores can be made pure with little performance hit as updating the world record will be fast compared to updating the store itself

If this is true, this would be a clear win. I'm not sure whether or not it is true though; for IntMaps the overhead is small, but for a mutable cache it might be a lot bigger. I don't know if GHC manages to optimize a State that doesn't change to the same performance as a Reader. How far from actually compiling is this (also why is there no CI :S)? I'd love to see some performance numbers.

Somwhat related; one thing I'm experimenting with is rewriting e.g. Get to

class Get m c where
  get :: Entity -> m c

which would allow the same thing since m could be State World or ReaderT MutableWorld IO. Unfortunately being this general requires a lot of trickery, so I'm not sure this will ever work.

@DavidEichmann
Copy link
Author

I've almost got this building now. I just need to get TH to create the world init function to be in m not IO. I have left the Cache store in IO due to it's performance characteristics.

@DavidEichmann
Copy link
Author

I think I've introduced some bugs :-( e.g. cmap needs to be updated. Initial runs of the benchmarks shows faster initialization (dono why) and slower updates (also not sure why).

@jonascarpay
Copy link
Owner

Initial runs of the benchmarks shows faster initialization (dono why) and slower updates (also not sure why).

I'm seeing similar results here #72 (comment). The way the benchmark numbers work out can be kind of weird. As long as the total time is still lower, I think it's fine. What kind of cmap bugs did you run into, did the tests catch them?

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

Successfully merging this pull request may close these issues.

2 participants