-
Notifications
You must be signed in to change notification settings - Fork 52
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
Switch entity tiles to use *mutable* arrays #30
Comments
I was looking into this and I can use a boxed mutable array like I'll also look into benchmarking the performance difference from making this change. |
|
I'm looking into this issue again after the I've tried this out using IOArray first. So
But I can't seem to get
The main addition to the current |
We may have no choice for performance reasons, but I think we shouldn't take the decision of making the game state mutable lightly. Once we do that we close the door to things like:
All these things can be done by snapshoting the world, but it will be more cumbersome. My (limited) experience is that when something is persistent you are more inclined to experiment with features like these. One thing we could do is turn world modification an effect and have two interpreters: a pure slow one, and a mutable fast one. This is reminiscent of the discussion about how to represent the store in #150 (comment). |
I have myself avoided mutable state in Haskell so far as the pure data-structures offered pretty good performance - I am not sure that this is the bottleneck. The cons presented by @polux also make me less excited for this change. If we can spare the time and effort, I would really like to see if we could not get good enough performance with an In any case it would be nice to have benchmarks running bigger robot programs to see what the improvements are.
|
Also maybe this could be significantly improved with saving&loading the world (#50) - we could put the loaded world into the immutable array and thus empty the changed |
I agree with @polux's comments above that mutable arrays will certainly push a lot of interesting ideas out. Since the main reason for mutable arrays for performance I thought of trying out the changes to at least benchmark the performance difference. I've take a stab at it in #278 using IO arrays and my conclusion is that IO is truly messy and it leaks everywhere. Currently the branch is not building because I've stopped at a couple of major roadblocks. The changes to the World module itself are relatively small. It's just that the logic becomes much more imperative. However the main challenges that occur because of this are -
Overall even as an experiment using IO Array has turned out to be very hairy and is still not building. I might have better luck with ST Array. I'm open to suggestions if there's a better way to implement it. |
I'm going to close this --- I think we're all agreed that adding mutable state is not a great direction to go in. Definitely still open to experimenting with other ways to get better performance, e.g. the suggestion to try |
Right now we store the world as a triple: a collection of immutable terrain tiles, a collection of immutable entity tiles, and a map specifying which cells have been updated from their original entity values. However, there is no good reason that we can't just use mutable arrays for entity tiles. Running the game already takes place in a monad; we just have to make sure that it supports the mutable array operations. This should hopefully make the implementation simpler and speed up the game as well.
The text was updated successfully, but these errors were encountered: