TUXDB - LINUX GAMING AGGREGATE
by NuSuey
NEWSFEED
▪️ GAMES
▪️ STEAM DECK ▪️ DEALS ▪️ CROWDFUNDING ▪️ COMMUNITY
tuxdb.com logo
Support tuxDB on Patreon
Currently supported by 8 awesome people!

🌟 Special thanks to our amazing supporters:


✨ $10 Tier: [Geeks Love Detail]
🌈 $5 Tier: [Arch Toasty][Benedikt][David Martínez Martí]


Stellaris Dev Diary #181 : Threading and Loading Times

Today's Dev Diary is a greeting from one of our Stellaris Programmers, Mathieu aka The French Paradox! "Hello everyone, this is The French Paradox (Stellaris Programmer) speaking! On behalf of the whole Stellaris team, we hope you've had a good summer vacation, with current circumstances and all! We're all back to work, although not at the office yet. It is going to be a very exciting autumn and winter with a lot of interesting news! We are incredibly excited to be able to share the news with you over the coming weeks and months! Today I open the first look at the upcoming 2.8 release with some of the technical stuff that we programmers have been working on over summer. The rest of the team will reveal more about the upcoming content and features in the following diaries. Without further ado, let's talk about threads!

Threads? What threads?


There is a running joke that says fans are always wondering which one will come first: Victoria III or a PDS game using more than one thread.
Don't lie, I know that's how some of you think our big decision meetings go Im afraid Ill have to dispel the myth (again): all PDS games in production today use threads, from EU4 to CK3. Even Stellaris! To better explain the meme and where it comes from, we have to go through a little history. Im told you guys like history. For a long time, the software industry relied on Moores Law, which states that a CPU built in two years will be roughly twice as efficient as one today. This was especially true in the 90s, when CPUs went from 50 MHz to 1GHz in the span of a decade. The trend continued until 2005 when we reached up to 3.8GHz. And then the clock speed stopped growing. In the 15 years since, the frequency of CPUs has stayed roughly the same. As it turns out, the laws of physics make it quite inefficient to increase speeds beyond 3-4 GHz. So instead manufacturers went in another direction and started splitting their CPUs into several cores and hardware threads. This is why today youll look at how many cores your CPU has and wont spend much time checking the frequency. Moores Law is still valid, but, to put it in strategy terms, the CPU industry reached a soft cap while trying to play tall so they changed the meta and started playing wide. This shift profoundly changed the software industry, as writing code that will run faster on a CPU with a higher speed is trivial: most code will naturally do just that. But making usage of threads and cores is another story. Programs do not magically split their work in 2, 4 or 8 to be able to run on several cores simultaneously, its up to us programmers to design around that.

Threading nowhere faster


Which brings us back to our games and a concern we keep reading on the forums: is the game using threads?. The answer is yes, of course! In fact, we use them so much that we had a critical issue a few releases back where the game would not start on machines with 2 cores or less. But I suspect the real question is : are you making efficient usage of threads?. Then the answer is it depends. As I mentioned previously, making efficient use of more cores is a much more complex issue than making use of more clock cycles. In our case, there are two main challenges to overcome when distributing work among threads: sequencing and ordering. Sequencing issues occur when 2 computations running simultaneously need to access the same data. For example lets say we are computing the production of 2 pops: a Prikki-Ti and a Blorg. They both access the current energy stockpile, add their energy production to it and write the value back. Depending on the sequence, they could both read the initial value (say 100), add their production (say 12 and 3, the Blorg was having a bad day) and write back. Ideally we want to end up with 115 (100 + 12 + 3). But potentially both would read 100, then compute and overwrite each other ending up with 112 or 103. The simple way around it is to introduce locks: the Prikki-Ti would lock the energy value until its done with its computation and has written the new value back, then the Blog would take its turn and add his own. While this solves the problem, it introduces a greater one: the actions are now sequential again, and the benefit of doing them on concurrent threads has been lost. Worse, due to the cost of locking, unlocking and synchronizing, the whole thing will likely take longer than if we simply computed both on the same thread in the first place. The second issue is ordering, or order dependency. Meaning in some cases changing the order of operations changes the outcome. For example lets say our previous Prikki-Ti and Blog decide to resolve a dispute in a friendly manner. We know the combat system will process both combatants, but since there are potentially hundreds of combat actions happening, we dont know which one will happen first. And potentially on 2 different machines the order will differ. For example on the server the Prikki-Ti action will happen first, while on the client the Blorg will act first.
#BlorgShotFirst On the server the Prikki-Ti action is resolved first, killing the Blorg. The Blorg action that comes after (possibly on another thread) is discarded as dead Blorgs cant shoot (its a scientific fact). The client however distributed the computation in another way (maybe it has more cores than the server) and in his world the Blorg dispatched the Prikki-Ti first, which in turn couldnt fight back. Then both players get the dreaded Player is Out of Sync popup as their realities have diverged. There are, of course, ways to solve the problem, but they usually require redoing the design in a way that satisfies both constraints. For example in our first case each thread could store the production output of each pop to add to each empire, and then those could be consolidated at the end. In the same fashion our 2 duelists problem could be solved by recording damage immediately, but applying the effects in another phase to eliminate the need for a deterministic order. As you can imagine, it is much easier to design something with threading in mind rather than retrofitting an existing system for it. If you dont believe me just look at how much time is spent retrofitting your fleets, Ill wait.

The good news


This is all nice and good, but whats in it for you in the next patch, concretely? Well you will be happy to hear that I used some time to apply this to one of the oldest bits of our engine: the files and assets loading system. For the longest time we have used a 3rd party software to handle this. While it saved us a lot of trouble, it has also turned out to be quite bad at threading. Up to the point that it was sometimes slower with more cores than less, most notably to the locking issues I mentioned before. In conjunction with a few other optimizations, it has enabled us to drastically reduce the startup time of the game. I could spend another thousand word explaining why, but I think this video will speak better: https://www.youtube.com/watch?v=a6MWyc0wIo8&feature=emb_title This comparison was done on my home PC, which uses a venerable i7 2600K and an SSD drive. Both were hot startups (the game had been launched recently), but in my experiments I found that even on a cold start it makes a serious difference. To achieve the best speedup, you will need to use the new beta DirectX11 rendering engine. Yes, you read correctly: the next patch will also offer an open beta which replaces the old DX9 renderer by a more recent DX11 version that was initially made by our friends at Tantalus for the console edition of Stellaris. While visually identical, using DX11 to render graphics enables a whole range of multi-threading optimizations that are hard or impossible to achieve with DX9. Playing with the old renderer will still net you some nice speedup on startup, the splash screen step should still be much faster, but youre unlikely to see the progress bar jump as it does with DX11 when the game loads the models and textures. Some of those optimizations have also been applied to newer versions of Clausewitz, and will be part of CK3 on release. Imperator should also benefit from it. It might be possible to also apply it to EU4 and HoI4, but so far my experiments with EU4 havent shown a huge speedup like it did for Stellaris and CK3. If you want to read more technical details about the optimizations that were applied to speedup Stellaris, you can check out the article I recently published on my blog. And with that I will leave you for now. This will likely be my last dev diary on Stellaris, as next month I will be moving teams to lead the HoI4 programmers. You can consider those optimizations my farewell gift. This may have been a short time for me on Stellaris but dont worry: even if I go, Jeff will still be there for you! Mathieu, aka The French Paradox"


[ 2020-08-27 12:48:02 CET ] [ Original post ]



Stellaris
Paradox Development Studio
  • Developer

  • Paradox Interactive
  • Publisher

  • 2016-05-09
  • Release

  • Strategy Simulation Singleplayer Multiplayer
  • Tags

  • GameBillet

     8.91 /

     

     
    Game News Posts 537  
    🎹🖱️Keyboard + Mouse
  • Controls

  • Very Positive

    (119848 reviews)


  • Review Score

  • https://www.stellaris.com/
  • Website

  • https://store.steampowered.com/app/281990 
  • Steam Store

  • The Game includes VR Support



    Linux [153.28 M]

  • Public Linux depots

  • Stellaris: Infinite Frontiers eBook
    Stellaris: Plantoids Species Pack
    Stellaris: Leviathans Story Pack
    Stellaris: Utopia
    Stellaris: Nova Edition Upgrade Pack
    Stellaris: Galaxy Edition Upgrade Pack
    Stellaris: Anniversary Portraits
    Stellaris: Synthetic Dawn
    Stellaris: Apocalypse
    Stellaris: Humanoids Species Pack
    Stellaris: Distant Stars Story Pack
    Stellaris: MegaCorp
    Stellaris: Ancient Relics Story Pack
    Stellaris: Lithoids Species Pack
    Stellaris: Federations
    Stellaris: Necroids Species Pack
    Stellaris: Nemesis
    Stellaris: Aquatics Species Pack
    Stellaris: Overlord
    Stellaris: Toxoids Species Pack
    Stellaris: First Contact Story Pack
    Stellaris: Galactic Paragons
    Stellaris: Astral Planes
    Stellaris: Expansion Subscription
    Stellaris: The Machine Age
    Stellaris: Cosmic Storms
    Stellaris: Grand Archive
    Stellaris: Rick the Cube Species Portrait
    Stellaris: Season 08 - Expansion Pass
  • Available DLCs

  • Explore a vast galaxy full of wonder! Paradox Development Studio, makers of the Crusader Kings and Europa Universalis series presents Stellaris, an evolution of the grand strategy genre with space exploration at its core.

    Featuring deep strategic gameplay, a rich and enormously diverse selection of alien races and emergent storytelling, Stellaris has engaging challenging gameplay that rewards interstellar exploration as you traverse, discover, interact and learn more about the multitude of species you will encounter during your travels.

    Etch your name across the cosmos by forging a galactic empire; colonizing remote planets and integrating alien civilizations. Will you expand through war alone or walk the path of diplomacy to achieve your goals?

    Main Feature
    • Deep & Varied Exploration.
    • Enormous procedural galaxies, containing thousands of planets.
    • Explore Anomalies with your heroic Scientist leaders.
    • Infinitely varied races through customization and procedural generation.
    • Advanced Diplomacy system worthy of a Grand Strategy Game.
    • Ship Designer based on a vast array of technologies.
    • Stunning space visuals.
    MINIMAL SETUP
    • OS: Ubuntu 20.04 x64
    • Processor: Intel iCore i3-530 or AMD FX-6350Memory: 4 GB RAM
    • Memory: 4 GB RAM
    • Graphics: Nvidia GeForce GTX 460 or AMD ATI Radeon HD 5870 (1GB VRAM). or AMD Radeon RX Vega 11 or Intel HD Graphics 4600Network: Broadband Internet connection
    • Storage: 12 GB available space
    RECOMMENDED SETUP
    • OS: Ubuntu 20.04 x64
    • Processor: Intel iCore i5-3570K or AMD Ryzen 5 2400GMemory: 4 GB RAM
    • Memory: 4 GB RAM
    • Graphics: Nvidia GeForce GTX 560 Ti (1GB VRAM) or AMD Radeon R7 370 (2 GB VRAM)Network: Broadband Internet connection
    • Storage: 12 GB available space
    GAMEBILLET

    [ 5951 ]

    4.44$ (78%)
    24.87$ (17%)
    16.52$ (17%)
    3.29$ (18%)
    0.80$ (90%)
    1.83$ (8%)
    15.90$ (20%)
    1.77$ (78%)
    20.65$ (17%)
    0.76$ (92%)
    4.59$ (8%)
    12.59$ (16%)
    25.79$ (14%)
    1.11$ (78%)
    9.19$ (8%)
    5.03$ (16%)
    3.00$ (80%)
    13.64$ (45%)
    1.15$ (81%)
    8.27$ (17%)
    4.87$ (19%)
    5.65$ (81%)
    12.74$ (15%)
    6.79$ (15%)
    11.03$ (78%)
    3.31$ (78%)
    4.00$ (80%)
    7.98$ (20%)
    1.11$ (78%)
    7.50$ (70%)
    GAMERSGATE

    [ 3154 ]

    2.81$ (81%)
    9.89$ (34%)
    0.45$ (92%)
    20.82$ (40%)
    6.0$ (70%)
    11.99$ (20%)
    1.5$ (90%)
    3.75$ (75%)
    5.0$ (50%)
    10.19$ (32%)
    33.19$ (17%)
    5.78$ (66%)
    6.74$ (63%)
    11.25$ (55%)
    21.59$ (28%)
    0.6$ (92%)
    0.53$ (92%)
    10.13$ (77%)
    17.49$ (30%)
    1.88$ (81%)
    2.63$ (62%)
    1.76$ (91%)
    0.38$ (92%)
    7.48$ (66%)
    1.5$ (85%)
    10.07$ (28%)
    0.75$ (92%)
    5.78$ (71%)
    19.79$ (34%)
    1.69$ (89%)

    FANATICAL BUNDLES

    Time left:

    2 days, 8 hours, 29 minutes


    Time left:

    25 days, 8 hours, 29 minutes


    Time left:

    7 days, 8 hours, 29 minutes


    Time left:

    38 days, 8 hours, 29 minutes


    Time left:

    44 days, 8 hours, 29 minutes


    HUMBLE BUNDLES

    Time left:

    5 days, 2 hours, 29 minutes


    Time left:

    5 days, 2 hours, 29 minutes


    Time left:

    14 days, 2 hours, 29 minutes


    Time left:

    21 days, 2 hours, 29 minutes

    by buying games/dlcs from affiliate links you are supporting tuxDB
    🔴 LIVE