I'm trying to revive the hazard lights mods for my own use, and I have managed to update them to use selection tools instead of the deconstruction planner trick they had used prior, getting me past the boot stage.
Unfortunately, it seems like the mod did something else really wrong during the control phase, since the garbage collection number went absolutely BONKERS. It's over 900(0)!
By comparison, without it it was in the 0.9 range.
So, what sorts of actions can end up creating excessive amounts of garbage?
What is Lua garbage, and how do I reduce it
Re: What is Lua garbage, and how do I reduce it
The render API has O(n) time for access with ID. So modifying anything is slow. Everything is in a big array, per mod. Removals might be O(n^2). n is the total amount of render objects existing that are created by your mod. Doing clear() to remove everything is fast in comparison if you want to remove everything since it just removes the whole array of objects as one operation. So in some/many cases it's faster to remove everything and then rebuild all render objects you didn't want to get rid of since removing 1 thing takes maybe 100x more time than adding 1 thing which is O(1).
In my mod ChunkyChunks (renders grids) I just try to reduce the amount of rendered objects (lines) by having looooong lines and using "dashed" lines in a somewhat clever way to get many lines per render object.
This thread is probably helpful: viewtopic.php?f=28&t=85885
In my mod ChunkyChunks (renders grids) I just try to reduce the amount of rendered objects (lines) by having looooong lines and using "dashed" lines in a somewhat clever way to get many lines per render object.
This thread is probably helpful: viewtopic.php?f=28&t=85885
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Re: What is Lua garbage, and how do I reduce it
I can see why it would be bad... That mod renders 4 lights per entity basically
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: What is Lua garbage, and how do I reduce it
I remember that the original bottleneck (with only one "light" per entity) used real entities instead of rendering because of how much faster it is to deal with them. Dealing with real entities you have to deal with removing them when the entity is removed though, but that got a lot easier since the introduction of LuaBootstrap.register_on_entity_destroyed. You also have to find a fitting entity prototype that can create light without requiring energy (aka void-energy capable?). And in case someone uses an entity-mover mod (like Picker Extensions) and you care about that kind of thing you'd also have to deal with moving the lights.
*If* the rendering is really the problem. I assumed you meant something quite different when you mentioned the garbage collector.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: What is Lua garbage, and how do I reduce it
I honestly have no idea why the garbage collector went bonkers, just that it did. Without the mod, it's at 0.9. With the mod, it's over 900.
Also, it seems like it already has picker compatibility so I won't have to deal with that.
Also, it seems like it already has picker compatibility so I won't have to deal with that.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: What is Lua garbage, and how do I reduce it
LuaRendering has that built-in. I was talking about if you were to replace that with entities for performance.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.