Efficiency with a functional paradigm

Since functional code, by definition, avoids variability, as much as possible, you can write a stateful program by deploying the state from the previous one over time. So, I write a game in F # exclusively in a functional style, and, of course, games usually have many, many states. I essentially use entries for game objects (like players), and I just map all of these states to get the next state. It works very well. But, as my game gets harder and harder, I worry that it will become sluggish because it copies every update. I am wondering how I can try to avoid these pitfalls in the future (not right at this point, since this is not so much of a problem).

So, are there any significant optimizations in the functional style that F # does not do for me, in particular, related to copying large pieces of data when only small parts can be changed? Also, is there something that F # has that I can take advantage of in the same way?

One more thing - these are my two main problems, which may not even be true. I would like them to straighten up:

  • Garbage collection. Since I end up copying thousands of records per second, there must be a huge amount of object generation, all of which are extremely short-lived, as I just throw away the old state. This seems like the likely cause of short but subtle jumps in the game every second or so.

  • Is F # effective at copying records with all but a few fields updated? If this is not the case, how can I increase the efficiency on my own?

+4
source share
1 answer

So, are there significant optimizations used in a functional style that F # does not do for me, especially when copying large chunks of data, if only small parts can be changed?

Are you really copying "big chunks of data"?

, . , , "" , , .

+4

All Articles