- Start a new sandbox world
- Place a constant combinator and open it
- Execute one of these command :
Performance on loading :Performance on saving :Code: Select all
/c local entity=game.player.opened script.on_event(defines.events.on_tick, function() if not entity.valid then script.on_event(defines.events.on_tick, nil) else for i=0,64,1 do local map=entity.get_control_behavior().parameters.parameters end end end)
Code: Select all
/c local entity=game.player.opened script.on_event(defines.events.on_tick, function() if not entity.valid then script.on_event(defines.events.on_tick, nil) else local chunk={} for i=1,15,1 do chunk[i] = {signal={type="item",name="iron-ore"},count=i,index=i} end for _0=0,64,1 do entity.get_control_behavior().parameters={parameters=chunk} end end end)
- Enjoy the UPS drop (I get around 20 UPS for each test)
[0.14.22] get_control_behavior() bad performance
- y.petremann
- Filter Inserter
- Posts: 410
- Joined: Mon Mar 17, 2014 4:24 pm
- Contact:
[0.14.22] get_control_behavior() bad performance
In order to create a mod that add programming I used constant combinators as the main entity that hold value and instructions, for it to work I need to read and write on them each ticks, when we start having a lot of them (30 entities) it start lagging, the culprit seems to be the get_control_behavior() method :
Last edited by y.petremann on Fri Feb 24, 2017 3:58 am, edited 1 time in total.
-
- Long Handed Inserter
- Posts: 90
- Joined: Sat Jan 21, 2017 12:01 am
- Contact:
Re: [0.14.22] get_control_behavior() bad performance
Yeah, I've seen the same issues, especially with recursive blueprints (https://github.com/justarandomgeek/fact ... t/issues/3). I'd love there to be a way to react to signals on every tick without bogging down performance.
- y.petremann
- Filter Inserter
- Posts: 410
- Joined: Mon Mar 17, 2014 4:24 pm
- Contact:
Re: [0.14.22] get_control_behavior() bad performance
The only way I've found for now is indexing only what we need and put it in a temporary table to limit the use of get_control_behavior()NiftyManiac wrote:Yeah, I've seen the same issues, especially with recursive blueprints (https://github.com/justarandomgeek/fact ... t/issues/3). I'd love there to be a way to react to signals on every tick without bogging down performance.
Re: [0.14.22] get_control_behavior() bad performance
Yep, that's Lua for you.
There's nothing special about that method other than your calling it a ton, it involves a ton of small strings and tables, and it's Lua.
There's nothing I can do about that - it's working as fast as it can.
There's nothing special about that method other than your calling it a ton, it involves a ton of small strings and tables, and it's Lua.
There's nothing I can do about that - it's working as fast as it can.
If you want to get ahold of me I'm almost always on Discord.
- y.petremann
- Filter Inserter
- Posts: 410
- Joined: Mon Mar 17, 2014 4:24 pm
- Contact:
Re: [0.14.22] get_control_behavior() bad performance
The thing is that for the mod that use them, it needs to read them each ticksRseding91 wrote:Yep, that's Lua for you.
There's nothing special about that method other than your calling it a ton, it involves a ton of small strings and tables, and it's Lua.
There's nothing I can do about that - it's working as fast as it can.
For now the workflow each tick is :
- Prepare memory cache (minimal data)
- Run each controllers instructions
- If memory is needed but not available in cache, load it from corresponding constant combinators (cache is a perfect match of get_control_behavior().parameters.parameters)
- Process data in memory cache (more than a thousand times)
- Save modified memory to corresponding constant combinators
Re: [0.14.22] get_control_behavior() bad performance
Well, documentation does not state it clearly, but this line:
Might be interpreted as that you can store the once obtained reference and just check its validity afterwards. I didn't test it yet.
Note: An control reference becomes invalid once the control behavior is removed or the entity (see LuaEntity) it resides in is destroyed.
Might be interpreted as that you can store the once obtained reference and just check its validity afterwards. I didn't test it yet.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: [0.14.22] get_control_behavior() bad performance
Yes, you can do that for virtually all of the objects gotten from Factorio. In fact you should always do that.Adil wrote:Well, documentation does not state it clearly, but this line:Note: An control reference becomes invalid once the control behavior is removed or the entity (see LuaEntity) it resides in is destroyed.
Might be interpreted as that you can store the once obtained reference and just check its validity afterwards. I didn't test it yet.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.14.22] get_control_behavior() bad performance
It's the absence of `valid` field in documentation on control behavior that caused my hesitations.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: [0.14.22] get_control_behavior() bad performance
http://lua-api.factorio.com/latest/LuaC ... vior.brief All of the extended types have the valid property that I can see.Adil wrote:It's the absence of `valid` field in documentation on control behavior that caused my hesitations.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.14.22] get_control_behavior() bad performance
Well, the base class, which I've turned to as a general reference, did not.
Also, LuaCombinatorControlBehavior misses one.
Also, LuaCombinatorControlBehavior misses one.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: [0.14.22] get_control_behavior() bad performance
The base class and LuaCombinatorControlBehavior can never be gotten in the game. You always get one of the derived types.Adil wrote:Well, the base class, which I've turned to as a general reference, did not.
Also, LuaCombinatorControlBehavior misses one.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.14.22] get_control_behavior() bad performance
You clearly misunderstand how people's mind works.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: [0.14.22] get_control_behavior() bad performance
It's an API: people have to have some basic level of understanding about how programming works if they want to understand how to use it correctlyAdil wrote:You clearly misunderstand how people's mind works.
If you want to get ahold of me I'm almost always on Discord.