Friday Facts #82 - Optimisations

Posted by kovarex on 2015-04-17, all posts

Hello factorio builders,
I hope you enjoy lists and numbers, because you are going to be fed by these today :).

The 0.11 has been declared stable

We know it is not perfect, but it got to a point, where the remaining problems are subtle or specific to a certain hardware/software configuration or specific mods. The marathon of 22 releases in the 0.11 is finally over, so we can fully concentrate on the new stuff.

The team expansion

The recent calls for additional programmers had its results and we now feel, that the amount of people is starting to be enough for this stage of Wube software. This is the list of the people that work on the game sorted by the time of joining our ranks:

  • kovarex full-time: The founder, mainly programming, managing programming and generating game ideas.
  • slpwnd(Tomas) full-time: The co-founder, mainly programming and managing, Tomas also takes care of most of the legal stuff, and shaves of the senseless ideas of kovarex.
  • Albert double full-time: The graphics guy, he is with us from the beginning.
  • cube full-time: Programmer and technical expert.
  • Pavel full-time: The graphics department reinforcement.
  • Daniel part-time: He is Composing the music and sounds for Factorio in the UK.
  • Rseding91 part-time: Programmer from the US, he is working only remotely.
  • Twinsen (Robert) full-time: Programmer from Romania, he moved to Prague.
  • Leon part-time: Artist from Netherlands, he is doing the theme-art.
  • Martin part-time: Programmer, he joined us recently.
  • Michal part-time: Programmer, he is going to join us in two weeks.
It is going to be 11 people already! I can really feel the speed-up, as several big changes are being prepared at the same time, let's see how well can we coordinate.

The 0.12 todo list progress

Let's sum up what we promised for 0.12:

  • Multiplayer enhancments (lag hiding, better pvp/forces support)
    Tomas is working on the lag hiding and it seems to have nice results, you can expect detailed description of it in the next fff.
  • First part of the endgame content. (Build rocket and send it to space).
    Robert finished the silo and rocket launching logic, the remaining part is to figure out the recipes for the rocket parts and details of the rocket assembling in the silo.
  • Chain signals for trains (More)
    Martin is still working on those, lot of details have to be finished, the work on the integration tests and graphics is supposed start next week.
  • Combinator and more circuit logic (The plans)
    We had a few talks about the combinator, we have some basic idea and we are discussing the details, Robert will start working on these soon.
  • Personal roboport
    0% progress
  • Optimisation of the game simulation speed (mainly transport belt simulation)
    I (kovarex) work on it, more details in the next paragraph.
  • New graphics of combat robots. (The preview)
    Basically ready to be merged in to the main branch.
  • Steam integration
    This is not technically part of 0.12 as we plan to go to the steam when the 0.12 is stable, but this time we decided to postpone it no more.
The list isn't so scary after all, so my optimistic estimate for 0.12 is 1.5 months from now, while slpwnd estimates 2.5 months from now. I know he is going to be right, but I still prefer to be optimistic and I also prefer to be pushed by deadlines.

The optimisations

For me, the beginning of the new major release development is usually tied to the game optimisation. The game could never be optimised too much, as every factory can be expanded. This is especially important now, when the multiplayer is in the game, as more players build more stuff, obviously.

Most of the time, the biggest drain of the game update logic is the transport belts. There are usually many of these, and their logic was straightforward, but very inefficient. Every item on the transport belt was individual in-game entity with collision box and position. Once the item on the transport belt was supposed to move forward, all the nearby items (all in the 2X2 tile area) had to be checked for collision. There can be a lot of items nearby, especially if there is another transport belt next to the existing one so it can result in huge amount of checks.

There are 18 items to be checked for collision in this curve for every individual movement:

For 0.12, I completely rewrote the internal logic of all the transport belt related entities (belt, underground belt, splitter). The items on the belts are no longer represented as individual entities. These are just very simple internal structures moving on small invisible "rails". Once the item on the transport belt is supposed to move, only the item in front of it has to be checked for distance.

Movement of the item just requires to check the item in front of it, instead of checking collision with 18 different entities.
The other advantage of this rewrite is, that we can now fully control the density of the belts and other properties without ever being worried of the belts being stuck, like in this bug report. The overall optimisation of this change was roughly 20% time reduction on the testing factory.

That combined with some other things we have done for 0.12, the update time is now reduced by 28% compared to 0.11. My dream would be to get to 50% so 0.12 would allow double factory sizes, but it is obviously harder and harder to optimise the game. On the other hand, it is more fun now, as it is starting to be more challenging.

I have been asked what is the distribution of the entity update time, so here are the results for the first 20 entities on the standard factory
EntityUpdate timePlans
Inserter18.01%Reduce redundant vector rotations by precalculations.
Transport Belt12.44%Improve cache locality and activation/deactivation logic.
Smoke9.66%Shorten lifespan of the train smoke, custom simplification of it's movement logic.
Crafting Machine6.97%(furnaces/assemblers/chemical plants/refineries). Implement the sleep/wakeup logic for these.
Solar Panel4.11%Merge solar panels into groups internally when they are in the same network.
Fluid Box3.68%
Mining Drill3.40%
Underground Belt2.80%
Logistic Robot2.60%

The thread for your comments and opinions is ready at our forums.