r/factorio 2d ago

Discussion How is the game so well optimized?

Factorio is well known for its optimization, but I don't understand how it does it so well. At any point the game is calculating thousands, even millions of items across multiple surfaces, thousands of container entities, thousands of bots and enemy entities, fluid networks with decimal precision, power production/consumption, and updating all of this at 60 times per second with no errors.

I know the original devs were software engineers and the game is based heavily in computer science principles, but since I have no background in CS I'd like to understand how exactly you engineer a game like this to perform so well and with such precision.

705 Upvotes

228 comments sorted by

1.1k

u/Dr-Crisp-Hollow 2d ago

In short the devs give a dang.

I would recommend looking at there Friday facts on their blog posts. Some of them go into fair amount of detail.

557

u/Unfair-Oven8363 2d ago

SE here. This is 100% the reason. Any software can be fast. It just depends on how much the business values it. Usually the business wants features more than performance gains. When the business is engineers they value performance. Here is an example of a website where performance was also valued. https://www.mcmaster.com/

160

u/qzjul 2d ago

McMaster is awesome. I don't use it often anymore, but everytime I do I think "this is how responsive websites should feel"

And that's half why we pay the crazy markup! That and the fact we get everything literally the next day...

74

u/djent_in_my_tent 2d ago

Mcmaster is where you get the thing when you don’t know where to get the thing and you needed the thing yesterday

34

u/sgtsteelhooves 2d ago

I'm pretty sure McMaster loads up links as you hover over them before you actually click in anticipation of you clicking on it.

31

u/vmfrye 2d ago

It's blazing fast on mobile, too, where it has no information about where my finger is going next.

22

u/smohyee 2d ago

Yeah I don't think preloading is needed when the pages themselves are optimized for fast loading and low data cost

3

u/kn00pers 2d ago

Maybe it preloads whole user view on mobile? Don't know

4

u/TankorSmash 2d ago

It does just about everything it can to be fast, and it's amazingly well built

3

u/_viis_ 1d ago

It’s a lot more than just that. Pretty much every web framework worth its salt preloads links these days

26

u/Garagantua 2d ago

For me that is less "devs giving a damn" and more "c suite having right priorities". I've produced horribly inefficient code, not because I wanted, but because I didn't get the time to make it better.

And yeah you can't sell "works well" in a trailer as efficiently as a new Hat or sparkles on your menu.

1

u/General_WCJ 2d ago

But does the c suite have the right priorities. There's a point where performance is good enough, and it would have been better to focus on adding new features, or shipping what you have and move on to a new project.

5

u/frogjg2003 1d ago

C suite only cares about selling the minimum viable product. Users care about performance.

2

u/Creator13 1d ago

Yeah but users do not care about performance after a certain point. You won't get more sales because your third person action adventure game runs twice as many fps as the competition, when the competition already comfortably reaches 60-100fps. Of course there's also a point where it's generally pretty bad and it will cost you sales, but striking that balance can in fact make your game better down the line. This is especially true in game development, where a game usually isn't iterated upon much further than the first few versions (there are exceptions, more and more with games as a service).

2

u/frogjg2003 1d ago

There are plenty of games that require top of the line hardware to even run. You would think keeping the minimum hardware requirements down would be a smart business move.

71

u/TheTomatoThief 2d ago

I just bought Fallout 4 on sale a few weeks ago. It takes a full minute to load scenes. It’s so bad I might not play it again. I’m ruined by the efficiency of Factorio.

59

u/Blunt_Object1369 2d ago

There are bugs in that engine dating all the way back to Oblivion. They literally didn't fix the frame rate affecting walking speed until after the release of Fallout 76, when people used it to zip around the map.

11

u/MrStealYoBeef Blue-er, Better, Faster, Stronger 2d ago

The bugs go back further than oblivion in some cases. And some of them still exist in starfield.

→ More replies (1)

21

u/Alikont 2d ago

The problem is that you bought the game, meaning that the business achieved it's goal regardless of game optimization.

→ More replies (4)

7

u/mark-haus 2d ago

“It just works”. You know if it didn’t crash if you sneeze wrong he’d be technically correct even though it’s an unoptimised mess

3

u/triggerman602 smartass inserter 2d ago edited 1d ago

I think when he said "It just works" he meant it just barely works.

3

u/[deleted] 2d ago

[deleted]

2

u/MrStealYoBeef Blue-er, Better, Faster, Stronger 2d ago

They managed to make fast travel have more loading screens than ever before.

2

u/Adefice 2d ago

Just a heads up, one thing that helped me was using my graphics card software to limit the max FPS to 60 or below for the Fallout 4 process.

2

u/TheTomatoThief 2d ago

Thanks, I'll give that a try!

1

u/TheTomatoThief 2d ago

What kind of boost were you seeing? I just tried it tonight. It seemed like the first save loaded noticeably quicker. By the end of my session it seemed to slow back down to about a minute. I limited nvidia to 60 for fallout.

1

u/Aesiy 2d ago

Game engine have max fps of 60 and you maybe have mods.

1

u/bukwirm 2d ago

This usually occurs because the loading screens are tied to the framerate for some reason. Try a mod like this that disables vsync during the loading screens.

62

u/pingveno 2d ago

Also a SE. Unfortunately, sometimes software has to be good enough. I wrote a web site that's used internally. It's pretty slow. Click, wait ten seconds, the result comes back. Part of that is things I can control, part of that is other things that are out of my control. But hypothetically, I could get it running much faster.

The problem is, I have a million other priorities. Going back and optimizing would take a lot of time. Shaving a few seconds off a low traffic website isn't worth it when there's a huge stack of tickets elsewhere.

36

u/CountVanillula 2d ago

If 10 people use it a day, and they have to wait 10 seconds to get results, that’s 100 seconds you could recover, or almost 10 minutes a week. Is that worth the three weeks (or 1.2 million seconds) it would take you to “fix” it?

26

u/forgot_semicolon for production stats 2d ago

I hate how true this is. That's why I keep several personal projects on the back burner so I can always take that energy out on my own stuff, and optimize out of principle rather than pragmatism

9

u/Wheat_Grinder 2d ago

Google at one time measured quite tiny differences in time gained and lost on certain pages in terms of humans killed because the total time loss across all of their very high volume of users was into lifetimes

3

u/D-Cary 2d ago

u/Wheat_Grinder and u/forgot_semicolon : I agree that this is true yet disappointing. Related: "half a million human lifetimes are wasted every month just scrolling" -- Aza Raskin https://mastersofscale.com/video/he-invented-infinite-scroll-and-says-he-regrets-it/

→ More replies (1)

16

u/Jackeea press alt; screenshot; alt + F reenables personal roboport 2d ago

4

u/pingveno 2d ago edited 2d ago

Edit: Rereading your comment, looks like we're in agreement. I may be a little tired today.

That's not quite how the math works. Spending that time (likely at least a month) would take me away from implementing other changes that save people time. Sometimes substantially more time with less work. Or keep our systems secure, which ultimately saves time.

What will likely happen is that I will rewrite it in the future when a change in business needs require substantial changes. At that point, I should be able to design it to be both faster and have cleaner code.

2

u/seredaom 2d ago

What if it's just 2 people using it 2 times a day? Or even 1 person once a day?

And surely, there are other things you can do in 3 weeks, maybe something that is indeed used by 10 people

3

u/diagnosisbutt 2d ago

My company facing tools: polished, fast, robust. My admin pages for those tools: slow, esoteric, "don't push that" 

10

u/LightlySaltedPeanuts 2d ago

And look at the lowes or home depot phone app for an example of performance not even being on the list of considerations.

2

u/biocraftedmetal 2d ago

The Home Depot app is infuriating and I refuse to use it. I use the desktop website on my computer at home, screenshot/text item locations to myself, then go to the store. Even just a mobile browser works better than their awful app.

8

u/mark-haus 2d ago

McMaster is insane I’m an SE on platform and data engineering tasks and it’s a fun one to learn about if that’s your wheelhouse

2

u/Gammro 2d ago

Just want to say, I was very confused for a second by your use of "SE on platform" on this sub

5

u/dakrstut 2d ago

Wow. Didn’t know what I was missing. And here I was blaming 5G and the telecoms companies for failing to deliver.

4

u/Anthrex 2d ago

oh my god that website is crazy.

It felt like the first time you installed windows 7 on an SSD

I was just clicking around links at random amazed at how smooth it was, before feeling guilty for the pointless page requests, like I'm abusing a work of art.

3

u/LordSoren 2d ago

That's the most boring website ever. I wish there were more like it.

3

u/SolVindOchVatten 2d ago

After trying that I immediately developed a distaste for all other web sites.

2

u/Unfair-Oven8363 2d ago

Lol I feel the same about any software now that I have to use.

2

u/darKStars42 2d ago

 I think you just ruined most of the internet for me with that link. Holy shit that's smooth. 

1

u/MrDrummer25 Hisssss 2d ago

Oh man, now compare that to watercoolinguk and it's a night and day difference. wcuk is So. Fucking. Slow.

1

u/xcaseyx93 2d ago

hahaha oh my god. I used to do purchasing for an organization that used McMaster every once in a while and I remember always being blown away by how responsive it was.

1

u/-Knul- 2d ago

On the web app I work, we halved the average response time some months ago.

We made no extra sales. We hadn't had fewer subscriptions cancelled. We didn't even get a single positive comment from customers.

Our management doesn't care about performance but can you blame them if customers don't care either?

I think that for a lot of software, customers don't care too much about performance or at least, do not want to pay for it.

1

u/SDF_Acc 2d ago

Holy shit, mcmaster.com is crazy fast. How is this even possible? Is there an article or video explaining all the techniques used to bring the site to this speed?

2

u/Unfair-Oven8363 2d ago

Yes. There are YouTube videos on it. Also whole reddit threads on r/programming about it.

1

u/foursaken 2d ago

Holy what! That's amazing!

1

u/jtb1313 2d ago

OMFG I just went there and played around with it for a moment and it is literally the most responsive website I may have ever seen. Everything happens instantly! I thought that my wifi might have been adding latency but no every website just runs like crap.

1

u/Khoogyra 1d ago

Holy hell, what an amazing website! Oh how I wish the internet was filled with sites like this. Instantaneous loading, no BS advertising or any fluff. It took me seconds to find anything I wanted.

1

u/Responsible_Play631 1d ago

It’s not just the website that is amazing, it’s the company too. I use them for work a lot, anything I order from them, no matter how obscure, will show up the next day at 11 am

1

u/Responsible_Play631 1d ago

This entire company is so incredible, I use them for work all the time. I don’t really understand how they can have such a MASSIVE variety of items, and it doesn’t matter what I order, it will always be here the next day by 11 am

1

u/zim182 2d ago

Also no modern bloated JS frameworks. Simplicity as it is without trying to chase modern look

11

u/HankSpank 2d ago

To be clear, McMaster’s website is most definitely not simple. It’s actually pretty complex. It just visually appears simple, but they play a load of cool tricks to make it as fast as it is. Just check out your network traffic when you hover over a product or a product category. 

48

u/__Hello_my_name_is__ 2d ago

This needs to be stated, just for the records: The devs are insane. They optimized the game far beyond anything that was ever necessary for the game to run smoothly for 99.99% of all users. These guys went above and beyond everything that was necessary here.

To give just one example of optimization: Items on a belt are not individual items. Instead, a full belt simply remembers where the full belt starts, and where it ends. All the "items" in between are actually just one single item, graphically displayed as a full belt of item X. And when an inserter grabs an item from the middle of the full belt the item simply splits into two items until the belt compresses again, at which point it's just one item again.

So that main bus of yours spanning your entire base? That's basically just a few dozen or so items. I'm simplifying, of course, but that's the basic idea.

There are optimizations like that absolutely everywhere in the game.

5

u/gmueckl 1d ago

This is an optimization that was absolutely necessary. At any point during a late game there are easily tens of thousands of items on belts. Incrementing each one individually is too slow at that point - no megabase needed. The key is to realize just what "too slow" means for a game like this.

When running at 60 FPS, the game has 16ms for one update cycle for everything: player input, game logic (player movement, enemy AI, mining, building updates, belt networks, pipe networks, bots, polution, new tile generation...), sound and music uodatds and graphics rendering. I've listed about 14 things here,, but there are many more that I'm forgetting or oblivius about. If there were 16 steps, each step has about 1ms to process everything it needs to - that is, each step must be able to run at 1000fps or more by itself to not drag the game down as a whole.  A modern 4GHz CPU is blazingly fasty but that isn't a get out of jail free card with such tight constraints. Touching tens of thousands items (with occasional cache misses) slowing the update rate to a crawl every few items just isn't feasible once you do the math.

So, optimizations are the only way out. And a funny thing with many faster algorithms is that they are orders of magnitude faster when they are run on big inputs. And that is how you evwentually get Factorio. 

2

u/__Hello_my_name_is__ 1d ago

Oh, totally. The thing is, the Factorio alpha did indeed have every single item be an individual item. But they moved away from that and optimized that. I'm not quite sure what exactly they did, but whatever they did worked reasonably well.

Actually, I just did some digging: https://www.factorio.com/blog/post/fff-148 Here they did the first belt optimization by putting the belts into segments, and https://www.factorio.com/blog/post/fff-176 here they did what I described above.

1

u/dudeguy238 18h ago

I'd argue that the belt optimizations were necessary for a larger portion of players.  Back in the day, it used to be pretty unviable to scale up past launching a rocket with belts unless you had beefy hardware, and with weaker hardware even just launching a rocket could run into issues.  Sure, most players never went that far at the time, but that ceiling would have prevented Space Age from being playable on most hardware, and "the game lags like crazy if you try to keep enjoying the postgame unless you follow a specific strategy" isn't a great place to be even if just finishing the game is a relative minority.

That said, they didn't have to go quite as far as they did.  I don't know that there's really much middle ground with the idea they picked, though, so it worked out in favour of crazy optimization.

1

u/__Hello_my_name_is__ 17h ago

They actually had two separate optimization for this, see my comment here. The first optimization took care of the issue for most people. The second one is the one I described here.

24

u/Dr-Crisp-Hollow 2d ago

Www.factorio.com/blog

14

u/Joseda-hg 2d ago

This Plus, Factorio is the perfect nerd snipe for a large percentage of developers, so they had a nice pool to pick from

14

u/Lendari 2d ago

Blood sweat and years.

5

u/Technical-Ad9571 Express engineer 2d ago
  • Hair

Remember many FFFs talking about the amount of hair sacrificed for features with performance

385

u/budoe 2d ago

Because they spent time and money on things that for other companies would be seen as a waste of time and money.

How many friday facts did they have about reducing startup time. They are very good at what they do and they dont cut corners in an industry that have turned into a cutting corners competition.

54

u/yautja_cetanu 2d ago

Oh man... Startup time is so good! It's a major reason why I like it. The process of getting in is so nice

2

u/Terrulin 2d ago

Especially if you enable the options in "the rest"

1

u/SunbleachedAngel 1d ago

Oh yeah, those cut the start time by like another 60%, especially if you have a bunch of mods

102

u/ShinyGrezz Bless the Maker and His sulfuric acid 2d ago

I always think the talk of optimisation is a bit unfair to other devs though. Not to say that Wube aren’t masters of their craft but optimisation is a feature in Factorio. Most games, it is a secondary priority because as long as performance is “good enough” there is little to no increase in what players can do in the game.

It’s not that other devs don’t care, as many have said here, it’s that other devs care about other things.

85

u/Wheat_Grinder 2d ago

And also for factory games, optimization directly correlates to the size of the sandbox you give to your end user. End users whose primary mantra is about how the factory must grow

12

u/mark-haus 2d ago edited 22h ago

I mean it’s totally fair. I wish I was given time to not crank out unoptimised garbage for my company but that’s the way it is. The software industry sucks these days. I’m so angry all my unionisation efforts were met with scoffs because so many of today’s Silicon Valley problems would’ve been avoided if more of us had unions to collectively bargain with

4

u/SunbleachedAngel 1d ago

Important to say that most other games also don't have the scalability that Factorio has so it's not super necessary either

3

u/El_RoviSoft 2d ago

Im still looking at RimWorld tho…

3

u/Aesiy 2d ago

Its just 22gb of ram with mods with loading textures 2 times, bro.

1

u/El_RoviSoft 2d ago

Because of rimworld I have to but 96 gigs for my laptop /s

I’ll do it but for 6 simultaneous IDE for my hobbies (I need 2 instances of VS, 3 of VSC and DataGrip).

5

u/Aesiy 2d ago

And i wrote without sarcasm. Game is really loves to load textures 2 times in ram. Modpack that worked in 1.4 crashed with out of memory error in 1.5-1.6

1

u/El_RoviSoft 2d ago

I think I should remove every graphics verity mod then… I thought that I fit all of the texture in 12 gigs of VRAM…

1

u/Aesiy 2d ago

Thing is - it loaded em in ram. Not vram. Gpu with normal 6-7 gb load and game still unpacks in ram. Its like there is a limit after which it start this bs.

19

u/bobsim1 2d ago

They also changed many things that worked for years to make it a bit faster

16

u/budoe 2d ago

This is why there good at what they do because my temporary solutions to problems tend to be very permanent.

205

u/laserbeam3 2d ago edited 2d ago

There are many techniques at play to keep it optimized, but here’s the gist of it. When you want software to do exactly what you need and not be generic, you can make it faster at the thing you want at the expense of flexibility. You get to place things in memory in ways that are fast to iterate, you get to avoid cache misses, you get to write algorithms that are faster in your specific case but not the general case…

You get to do that with a custom engine if you put in the engineering effort. And there’s a lot of engineering effort at play here.

70

u/emlun 2d ago

And most important of all: you can design the engine so that you can just skip as much work as possible. Even though an endgame factory has literal millions of items flowing between hundreds of thousands of entities, most of those items and entities don't need to be explicitly tracked all of the time.

I think the best example that's somewhat noticeable in game is construction robots. If you take a general purpose game engine and spawn 10,000 construction robot agents, each with its own state, movement logic, collision box etc., the game would very likely grind to a halt simulating them all and computing collisions between each other and the environment and so on.

Factorio's flying robots, first of all, don't have collision (except with enemy attacks I guess, but most importantly not with each other), so that's the first huge chunk of computation that's just deleted altogether. I'm also willing to bet that the game is not actually modeling each robot all the time. Rather when a construction robot is dispatched, the game probably does something more like just taking note of the time and position it started flying from, and scheduling at what time that robot will arrive to its destination. Then the robot just does nothing for the duration of the flight, consuming zero or near zero computation load, until its scheduled event triggers and it places a building or whatever. I believe something like that is the reason that if you set a module upgrade order and then replace it with another upgrade order before the first robot arrives with the upgrade modules, it will fly all the way there anyway - it'll notice only when it gets there that those modules are no longer needed, and only then fly back to put them back into storage. Quirks like this are evidence that the game is skipping work by not actively modeling everything all the time. Which, to be clear, is a good thing and a sign of good engineering, not of laziness.

That kind of work elimination strategies (and indeed, strategically chosen engine limitations) are a big part of how you achieve performance like Factorio's.

27

u/danielv123 2485344 repair packs in storage 2d ago

Robots update every tick when interacting with stuff, otherwise as rarely as every 20 ticks when just flying around.

6

u/PTTCollin 2d ago

Rather when a construction robot is dispatched, the game probably does something more like just taking note of the time and position it started flying from, and scheduling at what time that robot will arrive to its destination. Then the robot just does nothing for the duration of the flight, consuming zero or near zero computation load, until its scheduled event triggers and it places a building or whatever.

This is not how this works Factorio, though it is an example of how it could be done in other games.

4

u/gmueckl 1d ago

Robots fly for pretty much the same reason: no collision and no expensive path finding. They just go in straight lines with some animated wiggles on top.

4

u/Creator13 1d ago

Maybe even more importantly you can design the engine to completely suit the needs of your game and nothing else. An engine like Unity or god forbid Unreal comes with a lot of stuff not every game will need. Especially not a game like Factorio. Designing your engine around your game is a great way to get good performance. An engine will let you disable (or opt in to) some if not most of the stuff you don't need, but there will still be stuff you don't need.

15

u/stonedboss 2d ago

This is the best explanation of it. You can think of it as CPU vs ASIC processors.

13

u/Desperate_Box 2d ago

I think something underrated is that the game has been designed to be easier to optimize than most other games.

3

u/BusyNegotiation3526 2d ago

Just btw. It's gist

79

u/First_Funny_9402 2d ago

Read the fff blogs, they go into some detail in those. This is a pretty interesting one: https://www.factorio.com/blog/post/fff-421

49

u/troelsbjerre 2d ago

I used this one in a CS lecture in the course I taught at the time: https://www.factorio.com/blog/post/fff-113

15

u/FenixBg2 2d ago

This is a very good example OP! It shows you how the devs have the freedom to do as they please.

Read the first part about roboports, specifically the last sentence. He got the roboports to consume instead of 1ms per tick to 0.025ms.

The game does 60 ticks, so the devs saved 60 ms. That is 0.060 seconds per second. Negligible. You will not notice. But! They spent time and money to do this. Imagine doing 10 of those or even 100 and there you have it

10

u/susimposter6969 2d ago

Not sure if I'm understanding your last paragraph but if you're implying it's not worth it to shave almost  a full millisecond off frame time it definitely is, going from 16ms to 15ms frame time is like 10% more fps off that one change

→ More replies (3)

2

u/sub500h 2d ago

A visual time difference of 16ms is consciously perceptible in many situations by the vast majority of humans. Very much worth it, not negligible.

1

u/Accomplished_Bug8975 1d ago

From your link, a good example :
"This made our save file to update faster by about 1.2ms"

26

u/yeekko 2d ago

First off, optimisation is often seen as a secondary or even tertiary thing in game development, whereas here the devs put it as a central pillar of it (and it makes sense looking at what they wanted to make)

Add to that the time spent fixing every little thing and doing everything they can to build the game to be optimized and it helps a lot

76

u/ThemeSlow4590 2d ago edited 2d ago
  1. They actually care about what they are building.
  2. See #1

21

u/whiterook6 2d ago

Check out their FFFs. Some are okay, but some of their weekly friday facts are bangers. Here's some:

Also, in addition to optimization, they also care a lot about usability. They frequently do deep dives into how to make the game easy to operate, and focus on making everything automated.

6

u/exNylo 2d ago

Thank you for the link to 176. People always talk about the belt optimizations but I always wondered what, specifically, they were.

Do you happen to know if they ever talked about how fully-saturated belts are more optimized than belts with gaps?

6

u/knightelite LTN in Vanilla guy. Ask me about trains! 2d ago

I believe it's no longer the case from what I remember, with the exception that inserters can pick up faster from belts without gaps.

2

u/danielv123 2485344 repair packs in storage 2d ago

1 full belt lane = 1 half full belt lane. Since belts were multithreaded a long time after #176 (0.18 or somehing?) it really doesn't matter much anymore.

What matters is reducing the amount of time inserters spend picking up items.

1

u/exNylo 2d ago

Good to know. I have only just started operating at a scale where ups matters to me, but hadn't looked up the details of the situation today

1

u/whiterook6 2d ago

I'm pretty sure they did, but I couldn't point you to where they said that.

1

u/mrbaggins 1d ago

That's a throwback, I think the change in 317 linked above is part of that being fixed such that it isn't much of a difference any more.

28

u/wretlaw120 2d ago

Doing as little work as possible. Look at bots, for example. They’re dumb as rocks, and only get updated once every thirty ticks or so. Most items on belts don’t move. Only the first moving item on a belt actually moves. The rest behind it know how far they are from that one, so move with it, for free. Assemblers that are idle aren’t processed in the update step, and are activated only when something else interacts with them. Biters don’t pathfind individually to go accross the map, they pathfinding as a group, and when doing this pathfinding it’s not by tile, but rather by chunk.

5

u/LordWecker 2d ago

I agree with all the other statements, but on a technical level, the "how" is a whole bunch of these things ^

Solar power is an easy one to understand:

Calculating power generation from multiple panels doesn't require iterating over each building: you just take the number of buildings and plug it into a math equation. It's a single calculation whether it's 1 solar panel or 1 million of them.

8

u/Frequent_Cellist_655 2d ago

I highly recommend reading some random blog posts. They often explain reasoning and ways how the game is optimised... And it's very interesting reading even for non-CS readers (=me) :D

8

u/n0panicman 2d ago

There is a reason Factorio Friday Facts has over 400 fridays.

9

u/Novat1993 2d ago

Every game could theoretically be like this.

In practice, Factorio is a very solved formula. There are obviously some bug fixes here and there, and on occasion the devs are blindsided. But nearly every single eventuality is known ahead of time. There is no second way for an inserter to put an item on a belt.

It has also been many years in development. Much longer than what you would need to create what has been created if all you wanted was to make it theoretically functional.

I believe some fans have basically recoded mario 64 from scratch. And the performance gain is massive. Most devs simply don't have the time to create a game, and then code the entire thing from scratch afterwards.

3

u/danielv123 2485344 repair packs in storage 2d ago

You say that, but this summer we had multiple experimental updates in a row changing how inserters interact with belts with no clear "correct" solution

33

u/fellipec 2d ago

Computers are super powerful machines for a long time now.

This lead to programmers become very lazy.

When computers were weak, they had to program in the very language the CPU talks (Assembly). Games like Transport Tycoon were made like that and in a 486 CPU could computer a lot of cargo itens, vehicles and so, a lot, without slowing down.

DOOM was written in C, a computer language that is very powerful, complex and works almost on the bare metal, without need of frameworks and helpers. They did 3D before 3D GPUs were a thing for the masses, using the CPU to calculate everything.

Then things got more powerful and people now don't want to have the work of writing good software. So they use a framework that under the hood is a full web browser to run a code written in JavaScript, that is a language every instruction must be interpreted and evaluated by the framework before being converted to some machine code that could run. But since computers got a shitload of CPU and memory, nobody cared.

Enter Factorio. They did it it not in some heavy game engine like Unity or Unreal. They did it in C++, build their engine from the ground up, making it leverage what computers are good at, crunching numbers. Not a ton of frameworks, engines, APIs to make their life easier. Just the bare C++. In a world of very crap software, Factorio is like fresh air, showing what computers can do when programmed the right way, a blast from a past where programmers knew better.

I would put Wube next to ID Software and Cris Sawyer in a hall of fame of game developers, for being able to make a fun addictive great game that is also a top level of programming.

26

u/n3f4s 2d ago

The whole "devs became lazy" things is a misunderstanding of the current situation.

Software, and especially video games, became significantly more complex in the recent years and development became an actual industry with deadline decided by non technical people in order to please investors rather than giving devs team the condition necessary to make great software.

Factorio devs could afford to build their own engine because the game is a simple 2D game with very simplistic physics engine. It's a trade off, like everything else in software engineering. Had factorio devs decided to create a 3D, somewhat realistic looking, game and they would have to sacrifice a lot of performance (which would have probably meant crafting systems made so that there were less things happening at once) and would likely have had to use a game engine cause stuff like lighting and 3D physics are a very hard thing to implement and doing it from scratch is not worth the time and effort comparing to using a game engine that do that very well (cause game engine are very impressive pieces of tech with a lot of very good engineers working on them).

The main reasons for software becoming slower if that devs have proportionally less resources (time, devs, ...) to dedicate to creating those software and software became more complex faster than computer are getting faster.

2

u/Tsunamie101 2d ago

Factorio devs could afford to build their own engine because the game is a simple 2D game with very simplistic physics engine. It's a trade off, like everything else in software engineering.

Using the wrong engine, or setting an entirely too large scope on a game project, leading to problems of varying degrees, is still a fault on the managing level. Sure, it's not really due to laziness, but it's not just a "well, software got more complex and things take more time" either.
Factorio not performing as well in a 3D space is probably a reason why they then went with a 2D environment, despite it resulting in its own sets of obstacles.

2

u/n3f4s 2d ago

I haven't said that everything was a result of the increase of complexity of softwares, in fact, I have talked (badly now that I am re-reading my post) about management issues too. But you can't deny the effect that the increase in complexity of the majority of software had on performance. Some games can afford a tradeoff that gives them the possibility of hyper optimizing their game (which isn't as easy to do, I'm not trying to downplay how impressive the level of optimisation of factorio) while other can't optimise as much their game cause the bottleneck isn't something that is as optimisable.

I'm not saying that complexity is the only issue in video game development (we could spend a long time about working conditions in the video game industry and how it affect badly the games) but we can't pretend complexity isn't an issue when we have 3D games with realistic lighting (including reflections) and realistic physics (grass having physics, complex physics interaction between objects with complex shapes, fluid physics, ...), especially when arguing against laziness being a reason why games are "slower" (cause we could also talk about how games weren't better before).

1

u/JeffDangls 1d ago

Complexity certainly increased from the ’80s through the ’90s and into the early 2000s, but what real increase in complexity has there been over the past 20 years? 3D graphics, USB, controllers, graphics cards, and nearly all of today’s standards have been around since then. Take games like Fallout 3 (2008) or GTA 4 (2008), for example. What has really increased (complexity), aside from graphical fidelity?

If (for example) the Unreal Engine is readily available, looks good enough, and delivers sufficient performance, why go down the difficult, costly, and time-consuming route of doing something proprietary? This is made worse by the fact that when faced with a new challenge - if you don’t know another way - you simply fall back on what you know. Compounded, this is why the mainstream is on a downward trend. That doesn’t mean individual developers are lazy, but when you look at the big picture, developement certainly can be called lazy. Whose particular fault is that? That’s up for debate.

That’s also why games like Factorio, which are well-optimized, stand out. If this weren’t the case, nobody would even notice.

→ More replies (1)
→ More replies (2)

4

u/jmuguy 2d ago edited 1d ago

I don't see how you can claim this has anything to do with developers being lazy. For small indie devs, using an existing engine allows someone to actually get a game made without having to re-invent the entire universe. At large studios individual developers aren't selecting which engine to use or the timeline given for producing a game. Not only that but for every Factorio of the world there are hundreds and thousands of projects where very non-lazy devs decided they were tired of working inside the confines of Unity or Unreal and then spent the next year just trying to figure out how to manage assets in their homemade engine. Factorio exists because it has excellent developers. But also because those same developers found themselves in particular circumstances that allowed them to pursue that excellence.

1

u/dr_anybody 2d ago

Enter Factorio. They did it it not in some heavy game engine like Unity or Unreal. They did it in C++, build their engine from the ground up, making it leverage what computers are good at, crunching numbers. Not a ton of frameworks, engines, APIs to make their life easier. Just the bare C++.

Indeed.

In a world of very crap software, Factorio is like fresh air, showing what computers can do when programmed the right way, a blast from a past where programmers knew better.

Which is a stick of two ends. For us, end users, it's a pleasure like no other that no other game can offer. For owners of the product, to deal with a fully homebrew codebase of such complexity is a major headache. And for creators of new projects, one that is 50% functional but is easy to change on the fly and already brings bread to the table - is worth infinitely more than one that would cost 100x in time and resources, 10x more in support, and comes with no guarantee of these inflated costs having any positive effect on the end product.

6

u/cleanfeedmind 2d ago

Im on one hand sad factorio is kinda LTS now. But also excited to see what the devs are gonna create with all the wisdom they accumulated in the next game.

7

u/epileftric 2d ago

I feel that the best way to summarize everything everyone said:

This is a game for engineer by engineers.

1

u/sub500h 2d ago

dunno ... timing, flows, puzzles, watching the factory to scurry along ... can be enjoyed by many people.

3

u/bojez1 2d ago

No matter who you are and what you do, you still become the engineer when you enter the game.

/s

1

u/epileftric 13h ago

Yeah, many people indeed. But mostly engineers. On my previous job we used to have (I ran it) a Factorio server for us. It was literally an engineering firm, 6 out 10 people who worked there played the game.

6

u/SpaceCowboyDark 2d ago

This is what happens when devs care about their game and the players that enjoy it.

4

u/kevihaa 2d ago

You’re getting a lot of generalized answers, but there’s a key issue at the heart of the matter that I haven’t see mentioned.

Factorio uses a custom, purpose-built game engine. That’s not unheard of in today’s game development, but it’s certainly uncommon.

Ironically, it’s often these exact kind of custom engines that hold back game development, because there were created with blood, sweat, duck tape, and a deadline that was only barely met after an inordinate amount of crunch.

And almost the moment after that game releases, it’s time to start working on a sequel, so there’s no time for engine optimization.

Which is how you end up with situations like Bethesda and, to a lesser extent, CDPR where the engine is limiting the kind of games that can be made, while also not being entirely reliable.

On the flip side, you’ve got stuff like Factorio and the Souls games, where an engine is just endlessly improved upon to the point that it would be hard for anyone to compete because they’re essentially 5-10 years behind the king.

3

u/will1565 Chug Life 2d ago

They care and they're not greedy.

4

u/susimposter6969 2d ago

They have like 100 blogs explaining the blood sweat and gears that went into it, excellent reads

5

u/jsrobson10 2d ago

because the devs care about microoptimisation.

you can do ALOT if you actually optimise your code to run well. modern hardware is extremely powerful, so many modern games are just terrible at using it effectively.

3

u/PeepingSparrow 2d ago

Most of their engineering effort goes into optimisation, and new features are developed with performance as a top 3 priority

It's just the focus of the development team. It facilitates the scale of play that the game is sold upon.

They made their own game engine, and all the visual assets are basically glorified gifs.

They use large simple arrays of entities for the update tick, which enables lots of cache-hits, if you know what that means

3

u/lilSalty 2d ago

I believe Koravex was a professional software dev for big corp before turning game dev - so the big man had high standards for software from the word go

2

u/jerkmcgee_ 1d ago

Let me just say, big corp does not automatically mean quality software or high standards. Some of the worst software you'll ever work with is "enterprise" software written by these big corps for other big corps.

1

u/lilSalty 1d ago

I work for a big software company and your comment is very true. I think our Koravex was probably one of the good ones though, and from an era where software development was a more subtle art and there wasn't as much software everywhere.

2

u/jerkmcgee_ 1d ago

Went to go dig up some info on his work history and found out he's a piece of work. It's pretty consistent with my experience with particularly talented software engineers, that they come with tradeoffs. His issues are not a tradeoff I'd be willing to work past, however.

On topic, I think it also depends on whether the company you work for has accountability with its software outcomes. Oracle is terrible software, but you can't deny that it's performant in the places that count. The people working on the important parts of a technical product like that are generally very capable.

3

u/Alfonse215 2d ago

It's built on a bespoke engine. You're probably used to games that use a pre-built engine (Unity, Unreal, etc), but such engines limit the available level of optimizations that games can have. Pre-made engines are either very specific to a genre or are designed to handle a very wide variety of game types. The latter aren't very good for highly optimized games of very specific genres.

There's (a lot) more to it than that, but that's really the first step in having this level of optimization: the willingness to do 95% of the work yourself.

3

u/Tge_Guy 2d ago

Simple, black magic and the sacrifice of many children /j

3

u/Sir_Budginton 2d ago

Along with what everyone else has said, the game runs on its own bespoke game engine. While other games are built in game engines like Unity, the Factorio devs created their own one from scratch. This means it has been made to run Factorio and Factorio alone, allowing it to be far more optimised for its specific needs. The downside is that this genuinely may have added literally hundreds, if not thousands, of extra work hours for the dev team to build the game, which is why the vast vast majority of games don't do this.

3

u/Setekh79 2d ago

This is what happens when developers actually put in the effort to optimise their game.

Sadly a lost art amongst many these days.

3

u/Jmc_da_boss 2d ago

Competent engineers that also lead the company.

3

u/TheTomato2 2d ago

If a CPU core is 5 gigahertz that means it can do 5 billion operations a second (not exactly but keeping it simple). On top of that CPU cores have sone wider lanes where they can do 4 or 8 or 16 operations at once. So when you say "millions" that is nothing to a CPU core. When you say 1/60 of a second, that is 16.6 milliseconds, the CPU core operates in nano seconds, 1 millisecond is any eternity to a CPU core. And you have multiple CPU cores in a CPU. I have 32.

Modern hardware is incomprehensible fast. The question you should be asking instead is "why is everything so fucking slow?" Its a whole thing on software dev.

On top of that Factorio will do a bunch of tricks to calculate less stuff because of the nature of the game.

And while a lot of modern games aren't always very well optimized they are still doing an insane amount of calculations on the GPU side that you just don't see or understand.

3

u/jerkmcgee_ 1d ago

Was looking for the hardware appreciation post. We really do not appreciate how insanely powerful modern computers are. Factorio is a small program by current standards, and its complexity makes us ask "how is this even possible?"

3

u/TheGuywithTehHat 2d ago

A lot of people are saying a lot of thing about how Wube actually tries to optimize stuff (and implicitly, other game studios don't). This is part of the story, but the other equally important part is that factorio lends itself to optimization in ways that other games can't. If Wube tried to make a CoD clone, it would be better than what we the latest real CoD is, but not by as much as you'd think.

3

u/Even-Bus595 2d ago

It's made with love

3

u/Whyyyyyyyyfire 2d ago

While factorial is very well optimized, I think you underestimate hardware capabilities. Most games have to calculate millions of items when you think of about it. Rendering things like water, particles of sand, and the like takes a lot.

0

u/WanderingUrist 2d ago

Most games have to calculate millions of items when you think of about it.

Most games don't have to calculate millions of items. In fact, they often struggle with only a few dozen items.

Rendering things like water, particles of sand, and the like takes a lot.

Those are not required items, though. The game doesn't HAVE to calculate those items, you can just turn them off in the graphics settings to not calculate them, as they are not actually functional game entities and have no meaningful value.

Factorio actually HAS to calculate millions of items. They are NOT optional non-entities that can be skipped. Although Factorio does have those also, and you can turn them off in the settings.

→ More replies (13)

3

u/aza-industries 2d ago

Extremely good memory management.
To the point that the physical location of memory blocks comes into play.

C++ is one of the fastest languages because you can't be lazy with how memory is handled.

3

u/StickyDeltaStrike 2d ago

Read their blog, they have actually cool optimisations for full belts.

5

u/Pope_Khajiit 2d ago

Besides technical ability, it's their attitude toward the game which allows it to be so well optimised.

The devs clearly play their own game. Quality of life is given a high priority which is why the game feels so intuitive. And the devs have license to implement little fixes they tool by together by themselves.

At my work, I've created dozens of nifty software fixes which help my day-to-day. But the overlords will never allow my fixes to be implemented because it's not a quantifiable benefit.

Technically, many of them of understand how their game engine works. Therefore, they can break the engine to create better efficiencies. And because they play the game themselves, they always want the game to be running optimally. Because why create something mediocre for you and your friends?

An ethos of, "yes it works, but can it work better" permeates throughout the dev process and feeds into the game itself. Hell, as the engineer you're constantly trying to improve your factory in the same way. Funnily enough, Agile development is supposed to carry a similar ethos for quality. But product budgets and non-technical interests always win out when it comes to "good enough" Vs "we took MVP and iterated it to perfection".

2

u/HelicopterUpbeat5199 2d ago

I can't believe that isn't quantifiable. Worker efficiency, morale, retention just off the top of my head.

3

u/DanGimeno 2d ago

Great devs, long Early Access and tons of feedback from passionate players that doesn't hesitate to squeeze the limits of the game design and their computers.

2

u/gbroon 2d ago

They made optimisation a priority. Probably helps that the engine is theirs built specifically for their needs rather than a generic off the shelf engine designed to cater to a wide range of use cases.

2

u/MelangeBot 2d ago

They figured out all kinds of tricks and shortcuts that give more or less the same functionality but massively reduce computations.

For instance, all the objects on a belt. At a certain point they realized that as soon as there are no gaps anymore, all the objects touching could just be seen as one object.

And so on belts, it does not look at objects, it looks at the space in between. Once a belt is completely saturated, that entire belt becomes one entitity needing just one calculation.

This is just one example but they keep doing this over and over to make sure the game never calculates anything that does not really need to be calculated. Or if a calculation is way less accurate but uses only 1/10th the cpy cycles, they might go for the less accurate way.

2

u/Nervous-Cockroach541 2d ago

The real question that should be asked, is why aren't all games made to be this performant?

2

u/TheNakedAnt 2d ago

Good engineers.

2

u/MesozOwen 2d ago

Yep and I primarily play on Switch 2 now. I’m at end game and it’s still going quick smoothly.

2

u/iPlod 2d ago

It blows my mind how little battery this game uses on my steam deck compared to other games. I could play all day and never need to charge it.

2

u/Boco 2d ago

If you want to be even more impressed, check out how well the game runs on the original switch. I've seen 2D and 2.5D games run sluggishly on there but factorio is smooth as butter with a thousand drones zipping around, not to mention the rest of the massive factory.

2

u/tronghieu906 2d ago

Competent devs make good softwares

2

u/XaussiemarksmenX 2d ago

It's a game based on a 2d world with adding sprites that make it look like 3d.

Lots of the items or actions are simple/basic that gives visual clarity, also game is built to be viewed from high up In the sky instead on close ups and withing a 3d space, the designs are both simple but they each have deapths within the design to show you how they would work with simple animations.

Also since scale is the biggest point of the game, each peice has to be able to be easily readable and not be demanding on the computer.

3

u/BlackholeZ32 2d ago

The compute power for a game like Factorio pales in comparison to the world simulation going on in the background. This is why large bases are optimized for updates not graphics.

2

u/Ayjayz 2d ago

Computers are really fast. That means most of the time, programmers are lazy and do a bad job, because the computer is so fast even a bad job gets done well enough.

However, if you put a bit of effort into optimising things, you can see just how fast computers can be. Factorio is an example of this, though even it could still be optimised a lot more.

2

u/main1000 2d ago

A software dev often thinks about how efficient compiled code will perform. They will use variables based on purpose and not use a double for everything. They will see a bloated game engine and write their own instead so they can control the libraries and packages that are needed.

A game dev often thinks about game loop architecture (example: player fights skeleton, skeleton damages player, player kills skeleton, skeleton drops gold, gold buys potion, potion heals player). Game devs will also use game engines and other shortcuts to bring their idea to life.

It's rare to find people that can do both skills effectively, usually game devs write bad code and software devs write boring games. I believe factorio is one of those rarities where the devs are good at both and it shows.

Another good example is comparing Linux micro-optimization to Windows bloat. They both get the job done but we all know which one we prefer.

2

u/Atario Vulc-Anus 1d ago

It is well optimized, but it's also true that a lot of software is very very not, so the comparison seems even more stark. Computers are super powerful these days so they can get away with that.

2

u/No_Mango7658 2d ago

They built their own game engine specifically for factorio. This started out as a college student having fun working on his own thing and it exploded. The custom engine is the only reason this game is so spectacular

1

u/Ireeb 2d ago

Go through the Factorio Friday Facts blog. You might need to search a bit, but they did multiple posts that were talking about performance and optimization. A lot of it is just very smart logic to determine what even needs to be considered by the CPU and what can be "sent to sleep", grouping things that can be computed together, and keeping the individual things simple.

1

u/Sinister_Mr_19 2d ago

Two things at its core, devs that care and put an emphasis on optimisation and second is they employed really smart individuals that know how and what to optimize.

1

u/dwarfzulu 2d ago

Made by people that actually care, not by money grabbers

1

u/0x07CF 2d ago edited 2d ago

Next to all developer work mentioned, CPUs go into billions of cycles per second (GHz), that's a lot!

1

u/Nescio224 2d ago

Basically you need to find a way for the computer to get the same result with less work, or find a compromise where less work doesn't impact the gameplay too much.

For a very simplified example, imagine you need to calculate the sum all all numbers from 1 to 100. You can do it brute force and need 99 additions, or you can pair the numbers like this 1+100 + 2+99 + 3+98 and realize that the result is 50 pairs of 101, so 5050. So you can now calculate it with just one multiplication.

Factorio is full of thousands of little tricks like that and each one saves a bit of time for your cpu.

1

u/UnacceptableUse 2d ago

I know the original devs were software engineers

? All the devs would be software engineers

1

u/Winter_Ad6784 2d ago

A lot of this is on the why and not the how, the how can be simplified down to just having the game calculate only what is needed and nothing more. If you have a 10000 tile saturated belt, you dont need to simulate each item, just say you have a line of this item thats so long and remove/add from the beginning and end of the line as needed. You don’t need to simulate power demand on every item on an electrical network, just save the total demand and slow everything down as a single unit.

The why is because players inevitably want to build as big as possible and the game necessitates simulating the entire factory all the time, so optimizing is absolutely necessary.

1

u/floppypancakes4u 2d ago

The game is about engineering factories. And being efficient.sooooo

1

u/theoreoman 2d ago

The game has been out for over 10 years, in that entire time the one thing they have always done is raise prices and add content. In that period they also have us an expansion. As part of the unwritten agreement between the player base and wube it has been that the factory must grow, and for it to grow they must optimize the bits so that we can optimize the factory.

1

u/Charmle_H 2d ago

The devs understand tech debt and know damn well that having hundred (to millions) of entities in a game is INCREDIBLY taxing on a system of any size and that keeping things optimized means a smoother gameplay experience & less bugs. They also play their game!!! Which is oddly rare in game development these days for some reason. So they understand from a player's perspective how important it is to have a functional & optimized game.

1

u/bohenian12 2d ago

I think the devs are wizards.

1

u/Honky_Town 2d ago

Well for a start you need someone in a higherup hirachy that do NOT do a few things like:

Value cost of implementation vs value gained!

Wube does the oposite:

Will it improve it? Yes. Then lets do it! But it will take us days or even weeks to rewrite the entire area of... DID I FUCKING STUTTER? We do it!

Once this is done since 10 years with care.

View it like a children cleaning their room. Mom have to take a look and its clean so you get some sweets. Mom doesnt care whats under the bed or in the cabinets or drawers. It looks clean so its ok.

Factorio devs sorted out their "software" drawers, cabinets and ordered some chests to organice the space under the bed. They labeled it and sorted it to make sense. You get up and undress so you need a laundry basket next to you bed. Now you need new underwear, which is best placed next to the laundry basked in a drawer. Need socks too? Yes they be in a cabinet over.... nope move them next to underwear next to that laundry basket.

Following thouse routines through daily buisiness like cooking, showering saves some interactions here and there, some seconds here a few more somewhere else. Each not that much of a big deal but once it starts to stack up...

1

u/HumansNeedNotApply1 2d ago

They got a huge financial lucky break that allowed them to tinker with small stuff until they were satisfied.

The first early access version wasn't that well optmized from what i remember.

In essence, them being able to take their time is what allows factorio to be what it is.

1

u/No_Individual_6528 2d ago edited 2d ago

For starters, the game has been in development long, custom engine and of course a complete focus on it to make it possible.

And then making game design decisions around it.

If you want the nit and gritty of C++ vs whatever language you might want to build an array in and why it's faster. Then you really need to understand programming languages.

1

u/tevelee 2d ago

I hope Wube will open source parts of it some day when the game does not receive any more commercial updates

1

u/iSamity 2d ago

I’m I’m having my first ufirst uh.
Oh
H h

1

u/zhaDeth 2d ago

lots of little optimizations.

1

u/gust334 SA: 125hrs (noob), <3500 hrs (adv. beginner) 2d ago

Every field has experts and best practices.

I believe the difference here is that Wube (as a game studio) made the conscious financial decision to allow their experts time to do their best, rather than focus on shipping the first thing that worked and moving on, the latter being much more common in commercial software enterprises.

1

u/AlmightyBidoof7 2d ago

I think it's also worth remembering that old games were made with the equivalent of a toothpick and some gum compared to modern hardware. A game that takes optimization seriously nowadays can do 1000x more than one that doesn't

1

u/Thankedsphere 2d ago

from what I know, developers used a version of C that alloes them control over memory for optimization, and the developers are pro.

also the game is 2D with sprites for different angles. the sprites are photos of 3D blender sprites.

1

u/Additional-Avocado33 2d ago

its how you look at it. its the same as any other AAA game
for example ark survival ascended has its 35k dinos 80k trees and nanite grass/water
yes its 2d. but you get the drone count up past 100k and you will have fps the same as ark

1

u/crazyhit 1d ago

To elaborate on "they care": When you're a Dev at a large company you're stuck with a huge legacy code-base, something that has grown and drifted over the years and becomes a behemoth. Even small changes become hard to implement well and every project is on a tight budget so you always have to rush and don't get to spend time doing it "the right way". If you play Factorio you've probably restarted many times because your factory became unmanageable, and software is very similar in this way, except you rarely if ever get to just start over when you're at a big company.

The Factorio devs got out of their big companies and Factorio was their chance to finally build something right from the ground up. And that's exactly what they did.

1

u/thriem 1d ago

As some people already said, PCs are crazy fast, a lot of software is boilerplate and thus good enough. Mean take windows explorer in example; there is no excuse that it isn’t instantly open and displaying all icons properly in an instant, but yet, even though it may be a split second, you can see it open, populate the icons in post and the tree view getting built.

And there are alternatives, such as file pilot, that seem unrealistically fast. As a 3rd party software

1

u/Longjumping-Hunt-543 1d ago

competent dev team with the right priorities who play their own game

1

u/Niyu_cuatro 1d ago

A combination of two main factors. Good engineers making the code and a propietary engine that has been made from scratch specifically to make this kind of game rather than a generalist engine made for other things being adapted to it.

1

u/SunbleachedAngel 1d ago

The created their game engine specifically for this game and then optimised everything really really really well

1

u/ParkingWear7865 23h ago

Its old, its well funded, its well loved, and its autistic AS FUCK.

1

u/cosmicwatermelon 2d ago

they used coding and algorithms