Do memory pools actually work in love2D
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Do memory pools actually work in love2D
A while ago after reading about memory pools ( https://gameprogrammingpatterns.com/object-pool.html ) I implemented it to my class lib and I can't see any changes. I don't really think it should increase FPS and I think the improvement is from memory? I like to think it works but does it? And how?
-
- Prole
- Posts: 15
- Joined: Mon Oct 26, 2020 2:02 pm
Re: Do memory pools actually work in love2D
As far as i know memory pooling is a good choice if youre creating and deleting objects during the gameplay, outside the load/initialize part of your game.
Allocating/deallocating memory is a expensive operation, thats why object pooling is good. You can reuse the memory previously allocated by another object.
If you are not creating/deleting objects constantly i dont see any benefits on using memory pooling.
Allocating/deallocating memory is a expensive operation, thats why object pooling is good. You can reuse the memory previously allocated by another object.
If you are not creating/deleting objects constantly i dont see any benefits on using memory pooling.
Re: Do memory pools actually work in love2D
Lua is a scripted language with "managed" memory so generally speaking we don't have memory pools.
We can't explicitly allocate or free memory in Lua because the Lua interpreter does that on its own.
Having said that, you can create your objects in advance to avoid slowdown during gameplay.
We can't explicitly allocate or free memory in Lua because the Lua interpreter does that on its own.
Having said that, you can create your objects in advance to avoid slowdown during gameplay.
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Do memory pools actually work in love2D
Thnx for the replies. What I got from this is that it should stop slow loading when new instances are made.(?)Though can't see changes in mine (I am creating lots of the same object like bullets and smoke)..
Oh and meRRy Christmas...
Oh and meRRy Christmas...
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Do memory pools actually work in love2D
New thought plsss!! thnxxx!!
If memory pools have an effect then shouldn't collectgarbage('count') be more or less steady(like maybe 5mb fluctuations)? Is that how it works. Mine isn't too steady(100mb flucs). Pls answer, pls thnx, thnx pls, answer thnx.
If memory pools have an effect then shouldn't collectgarbage('count') be more or less steady(like maybe 5mb fluctuations)? Is that how it works. Mine isn't too steady(100mb flucs). Pls answer, pls thnx, thnx pls, answer thnx.
-
- Party member
- Posts: 512
- Joined: Wed Oct 05, 2016 11:53 am
Re: Do memory pools actually work in love2D
Pooling can help, and I've successfully used it to reduce memory footprint in my projects, but it won't magically fix your memory issues if your objects generate a whole bunch of garbage (temporary tables, closures, etc). That garbage will pile up over time, until the garbage collector will run its sweep, which can be configured to suit your needs on a case-by-case basis (but isn't much of a solution, more like a hotfix).
We don't know what your code does unless you share it, so I recommend using something like profile.lua or jprof to diagnose where most of the memory build up is happening and when.
We don't know what your code does unless you share it, so I recommend using something like profile.lua or jprof to diagnose where most of the memory build up is happening and when.
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Do memory pools actually work in love2D
There isn't really anything wrong with my code, really. I just wanted to know if I'm doing object pooling right and if it has an effect (but thnx for the links).MrFariator wrote: ↑Sat Jan 09, 2021 11:36 pm
We don't know what your code does unless you share it, so I recommend using something like profile.lua or jprof to diagnose where most of the memory build up is happening and when.
So, besides other table junk, yes or no, Should the count stay more or less the same or is it normal to still fluctuate at the levels as if you didn't use object pooling???
By the way you can find my code somewhere here: https://love2d.org/forums/viewtopic.ph ... 5&start=40
Re: Do memory pools actually work in love2D
I believe that what MrFariator is trying to convey is that the pool only helps with the objects that are pooled, but there are many other possible sources of objects that are not pooled, but need to be cleaned up by the garbage collector, including strings, Löve objects, functions, coroutines and other temporary tables. Without the whole program, it's impossible to tell whether some part of it is generating objects that count as collectable garbage.
But even in the part you copied, in your class.lua, in function log(), you have this line:
That creates a temporary string resulting of concatenating the passed string and a newline character. This temporary string needs to be cleaned up by the garbage collector. As you call function log(), new strings will keep being generated, and memory will grow, until the garbage collector fires.
Similar temporary objects may be created elsewhere. There's been a recent discussion in this thread, related to whether it's possible to write a game that doesn't generate any garbage: https://love2d.org/forums/viewtopic.php ... 82#p237582 - apparently Xii is able to do so in his game, but it's quite uncommon and requires quite some effort.
But even in the part you copied, in your class.lua, in function log(), you have this line:
Code: Select all
file:write(str.."\n")
Similar temporary objects may be created elsewhere. There's been a recent discussion in this thread, related to whether it's possible to write a game that doesn't generate any garbage: https://love2d.org/forums/viewtopic.php ... 82#p237582 - apparently Xii is able to do so in his game, but it's quite uncommon and requires quite some effort.
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Do memory pools actually work in love2D
... yes...or ...no(unrelated to whatever problems I may have and (theoretically) besides all those other strings and stuff.) (You have made more things clear though. t)
Re: Do memory pools actually work in love2D
It is normal that it fluctuates if you generate garbage. It isn't normal if you don't. We can't know if you do or you don't, but it seems you do, judging by the snippet I've posted above.
Who is online
Users browsing this forum: No registered users and 164 guests