Fractal Softworks Forum

Starsector => Bug Reports & Support => Bug Reports & Support (modded) => Topic started by: Ced Riggs on August 02, 2020, 06:20:03 AM

Title: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 02, 2020, 06:20:03 AM
Heya,

I am playing Starsector with a buttload of mods, larger fleets, and 7GB RAM assigned to the game. My savegame file is currently ~80MB in size.
And yet...This manifests in colony docking dialog loading longer and longer. Interactions with the options in the menu itself go smooth and quickly, but if I take a tour across my currently seven colonies, I am experiencing a delay upwards of two seconds after docking.Masochistic as I am, I tried to push this as far as I can, and with three HVB fights in sequence, I reduced my FPS (travel mode) to less than three, and colony dialogs take about five seconds to pop up. Another three seconds needed to get from colony menu to colony management. At this point, the associated RAM is maxed out, my CPU is barely concerned and effectively idle. The only way to return to a functional game is saving (takes upwards of five minutes), quitting the game, restarting, loading back in. I can currently play one or two battles, or do two rounds of colony management before the loss of performance becomes annoying. One more battle/five more markets, and I have to restart. This is the end of most of my playthroughs, after a couple of days.

My conclusion is some sort of clean-up not happening and/or some sort of memory leaking that seemingly isn't caught.

Is there anything I can do? Is there anything responsible I could monitor?
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 02, 2020, 09:40:02 AM
Hi - hmm. If you can share your mod list, I think that'd be helpful - this indeed sounds like some kind of leak or similar issue. Knowing which mods are involved could help narrow it down over time.

It's possible to connect to a running copy of the game and check it for leaks - and what's causing it - but its fairly involved. Depending on how comfortable you are with that sort of stuff, there are some instructions here:

http://fractalsoftworks.com/forum/index.php?topic=7690.msg128363#msg128363

Basically, best-case scenario is this would zero in on a specific Java class in a specific mod.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: caekdaemon on August 02, 2020, 11:12:55 AM
Is there anything I can do? Is there anything responsible I could monitor?
I've got this exact same issue: ton of mods, larger fleets, lots of RAM allocated to the game, but then serious drops in FPS after battles until getting into the next battle, where the game will run fine, then get even laggier after getting back to the stratmap. I tried to figure out what it was by a little testing here and there, and at first I thought it was just a problem when two big fleets duked it out with one another, but after a while I noticed that it seemed to have something to do with the afterbattle looting as it seemed to get worse when I had more varieties of item in the cargohold, but don't quote me on that.

Unfortunately, I can't load the save now - Tahlan Shipworks has had an update which doesn't seem to be backwards compatible with that save, so it's KIA, so I can't load it up to rummage around. My current new save seems to have the issue as well, but since I'm flying a smaller fleet the problem doesn't seem to be anywhere near as bad until it builds up over a few hours of play. 
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 02, 2020, 01:11:14 PM
If you can share your mod list, I think that'd be helpful - this indeed sounds like some kind of leak or similar issue. Knowing which mods are involved could help narrow it down over time.
Every mod that works with the current game version and doesn't overlap. I am currently running about 90 mods.

Depending on how comfortable you are with that sort of stuff, there are some instructions here:
http://fractalsoftworks.com/forum/index.php?topic=7690.msg128363#msg128363
Basically, best-case scenario is this would zero in on a specific Java class in a specific mod.
Comfortable enough! Will do that extensively tomorrow and report back.

I noticed that it seemed to have something to do with the afterbattle looting as it seemed to get worse when I had more varieties of item in the cargohold, but don't quote me on that.
Quoted you on that on principle, and, that is a valid pointer. I will look out for that.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 02, 2020, 03:29:03 PM
Update: To get jvisualvm, I went and grabbed the current JDK; Java 14.0.2 (https://www.oracle.com/java/technologies/javase-jdk14-downloads.html) from Oracle.

That did not get me jvisualvm, as this has been removed in 2016, and @Alex post is from 2014. So I went an grabbed VisualVM (https://visualvm.github.io/download.html) (same guys, just, no longer associated with Oracle), clipped Starfarer to the VM, and went out to cause mayhem to find my leak in the wild. I fought endless battles, traveled across the universe, flipped markets and caused wars. Two hours later, I could still play fine, and never got to the point where I felt like, yupp, that's the ticket, time to heap dump. Some crazy battles had so many fighters that my rig started chugging, but as soon as the fight was over or enough carrier died, we were back to almost 100% performance. I did notice a very minor stuttering every ~3s that barely registered, like a loss of one or two frames every so often, but that was it.

Will monitor and see if I get this again tomorrow, so I can search for the leak.

Tentative first thought: Maybe JDK 14.0.2x64 fixed an issue JRE 1.8.0_131x86 was having? Will investigate further when it's not half an hour past midnight.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 02, 2020, 04:14:28 PM
Were you actually running the game using Java 1.8? You'd have to replace the jre/ folder that comes with the game, and edit the settings.json file to do that and disregard some fairly dire warnings about it causing instability and so on.

The version of Java you have installed on your system shouldn't matter, though, since the game will run using the jre it's bundled with regardless.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 02, 2020, 10:22:50 PM
... then it's not that, and I am back to square one of not knowing what the heckie. Thanks for pointing that out. I'll monitor performance, and if I have something, I now know what to look for via VisualVM - thanks Alex!

PS: You might wanna update that post with the links to VisualVM, the usage is analog enough that I could replicate all steps you mentioned in that program.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on August 02, 2020, 10:54:22 PM
You can also use the ConsoleCommands to take a heap dump, if you do that and put the dump in a public place I can take a look at it too.  I'm having similar issues (https://fractalsoftworks.com/forum/index.php?topic=18753.msg292800#msg292800) so another data point is interesting to me.

(also once you have a dump you can use EclipseMAT too, or Visual VM)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 03, 2020, 01:55:17 AM
You can also use the ConsoleCommands to take a heap dump, if you do that and put the dump in a public place I can take a look at it too.  I'm having similar issues (https://fractalsoftworks.com/forum/index.php?topic=18753.msg292800#msg292800) so another data point is interesting to me.

(also once you have a dump you can use EclipseMAT too, or Visual VM)

Once I can reproduce the behavior, I'll do both - an analysis like Alex described, and a dump for you to look at. I'll start a new playthrough and will keep an eye on it. That'll take some time (work, learning how to sprite, things), but I'll keep you posted here.

PS: Never had a GC issue, only degrading performance. Was always able to save, even in 3FPS scenarios.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 03, 2020, 09:19:37 AM
PS: You might wanna update that post with the links to VisualVM, the usage is analog enough that I could replicate all steps you mentioned in that program.

Good call, thanks! Did that.

PS: Never had a GC issue, only degrading performance. Was always able to save, even in 3FPS scenarios.

Interesting. It taking that long - you mentioned five minutes! - still seems to indicate that there's something going on to slow it down, though. It's possible that the leak just isn't quite big enough to make it crash while saving but just big enough to make it slow, but, yeah, that'd be a fine line for it to walk. The really low campaign framerate seems to be almost be more indicative of some kind of cumulative problem with, say, the same script getting repeatedly added to the game or something that just over time adds up and massively slows it down.

Semi-related note: how big are your savefiles? The size of the campaign.xml, specifically.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 04, 2020, 09:30:11 AM
Interesting. It taking that long - you mentioned five minutes! - still seems to indicate that there's something going on to slow it down, though. It's possible that the leak just isn't quite big enough to make it crash while saving but just big enough to make it slow, but, yeah, that'd be a fine line for it to walk. The really low campaign framerate seems to be almost be more indicative of some kind of cumulative problem with, say, the same script getting repeatedly added to the game or something that just over time adds up and massively slows it down.

Semi-related note: how big are your savefiles? The size of the campaign.xml, specifically.
My lategame saves are well above 70MB, with my current one being roughly 82MB and climbing. I haven't had the time to start a new game yet to hunt for "that" behavior again, but there's a weekend approaching.

As for the fine line: I deliberately tried to keep going to see if I could eventually reach a GC crash. Yet even when the game slowed down to a crawl, no crash occurred. Additionally, since these performance drops were not in a smooth curve but more like falling down a flight of stairs, I usually had one big fight, maybe two if I felt masochistic, then I saved and restarted the game, plus clearing out my RAM standby list. Repeat this process in 2h to 3h intervals, depending on what I was doing - exploration without fights usually went well enough. But it never crashed on me, no matter how bad I let it get.

As these problems became a steady and constant issue, I made a save I declared my "last", and set sail for crash country. And yet, I never found the shores. The worst I found was the aforementioned ~3FPS and the ~5 minute saving of a game (time measured by the highly academic method of clicking Save & Exit, then getting water, going for a smoke, and coming back to watch the tail end of the bar fill up. The margin of error is 2 minutes). Then I posted here, set up VisualVM as instructed, and was ready to bug hunt like a pro. I picked a war with every neighbor I head, smashed into three IBBs, two HVBs, made Sylphon RnD homeless (Sorry, Nia. ;_;) and finally rolled into a High Danger Bladebreaker system, killing off battlegroups three at a time with a 300 DP battlesize - and Bladebreakers don't retreat.

The battles slowed down and stuttered over fighter spam and particle hooray. But as soon as the battles were over and the loot looted, the game returned to an almost normal state. It was slightly impacted, but nothing that'd make me consider the Restart Dance. It kept on chugging. I have nothing in my hands but questions.

The only thing I did between my first post in this thread and my VisualVM setup was installing JDK 14.0.3 - same mods, same vmparams RAM settings, same save file.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 04, 2020, 11:04:36 AM
Thank you for elaborating. Not much to add on my end, aside from this being odd. I almost feel like it's a combination of multiple issues. At a guess, some of them clearing up after installing JDK 14 is probably a coincidence. (You didn't happen to reboot or something around the same time? Depending on how often you reboot, that might've factored in...)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: caekdaemon on August 05, 2020, 03:08:32 AM
Been continuing on that new save I mentioned earlier in the thread and it has just started to get the slowdowns, too. I haven't done anything with the JDK or anything like that, so I can't comment on that, but just like Ced, the game gets increasingly laggy after battles and takes longer and longer to save. The only difference to me seems to be that I get my problems from fleets and fleet battles, whereas they get it from colonies like they mentioned back in the OP.

And oddly enough, it doesn't seem like a memory leak, either: I checked the console from the mod, and it says the game is only using 3.3GB out of the 6.9 I've gave it, so that doesn't seem like it'd be the problem...except a hunch had me try something and check on Task Manager, which helpfully says that the game is actually using 5.6GB instead. I don't know if that kind of discrepancy has something to do with this or not, but it might be something that helps as it'd put a smile on my face if I didn't have to restart the game after every hour or so :P
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 05, 2020, 05:23:49 AM
You could still try that VisualVM monitoring that Alex mentioned, see if you have a leak or nah. Considering that Starsector was first released (in Beta) in 2011, it is entirely possible that our contemporary rigs can keep going with a leaked campaign engine. I could imagine that current gen rigs simply shoulder that and keep going, but Alex might be able to shed light on that. I am just making *** up at this point.

In my new, tiny playthrough, no adverse performance has become apparent yet. I'll keep an eye it, though.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on August 05, 2020, 09:17:11 AM
I too (as well as a bunch of people on Discord) have seen this post battle slowdown.  It's usually after a large battle, but not always.  From looking at stack traces during the slowdown I *think* it's something in the economy getting stuck in an event driven loop.  Something like:
X Happens, triggers Y Update
Y Update happens, triggers X

Maybe not that simple, but it seems to be a pure CPU issue.  I could be entirely wrong about this, but when I looked at the stacks, the only thing that seemed to be happening consistently was an econ update, but maybe that's always happening enough that I'm totally wrong.  But what I am pretty sure about is it was a CPU bound issue, not a memory issue.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 05, 2020, 09:42:54 AM
It's possible to directly trigger an economy update. This should only be done from code triggered by UI interactions (where dropping a frame or two won't matter) but I suppose a script that does this on the regular could result in slowdowns. This may be something to look out for - scripts that call EconomyAPI.tripleStep() or .doubleStep() or .nextStep(). If a script does that not in response to a UI interaction, that's basically an error and an almost guaranteed frame drop.

Generally, the economy will update itself gradually in a way that doesn't impact the frame rate. E.G. the impact of a single tripleStep() is spread out over something like 9 in-game days.

Seeing a stack trace like you're describing could be enlightening - in particular where the economy update code is getting called from could shed some light on whether it's "normal" or troublesome. And it would also (importantly, if it's indeed a problem) tell us where it's being called.


You could still try that VisualVM monitoring that Alex mentioned, see if you have a leak or nah. Considering that Starsector was first released (in Beta) in 2011, it is entirely possible that our contemporary rigs can keep going with a leaked campaign engine. I could imagine that current gen rigs simply shoulder that and keep going, but Alex might be able to shed light on that. I am just making *** up at this point.

It's just a question of how much RAM is allocated. Generally if you've got 4-6 gb or so it'll be fine with a single CampaignEngine instance leak, maybe even two, depending on how much mods have increased the baseline memory needed for a single instance.

Thing is, though, a memory leak is not going to slow the game down unless the total memory used reaches very near the maximum allocated and it forces the garbage collector to "thrash" - meaning, it has to run often, but can't free up much memory because there isn't much to free up. This uses up a lot of CPU and would cause stuttering. It would also extremely likely result in an out-of-memory crash when you try to save, so since that's not happening, it seems fairly unlikely that this is the cause of the problem.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Cyan Leader on August 06, 2020, 04:54:42 AM
Posting here to confirm I'm getting this issue as well. Usually the battles are fine but the campaign layer is really laggy on a late game. Initially I thought it had to do with me hoarding weapons but I'm not sure. Usually restarting the game alleviates it but it is very annoying. I allocated 4 gigs to the game of RAM (java.exe -XX:CompilerThreadPriority=1 -XX:+CompilerThreadHintNoPreempt -Djava.library.path=native\\windows -Xms4096m -Xmx4096m -Xss1024k -classpath ) but through the task manager I have never seen it use more than 2.8g, which is odd. I have 16 gigs.

Running with a lot of mods though.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 06, 2020, 09:05:43 AM
(Posting the mod list can be helpful in the interest of narrowing down where the problem is, if you don't mind. The game should print the modlist to the log on startup.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Cyan Leader on August 06, 2020, 06:39:38 PM
I can't find that on the log but I typed them out:

Spoiler
AI Core Production 1.0.0
Audio Plus 1.1.1x (old version which I modified to include other music)
Better Colonies 1.4
Commissioned Crews 1.9
Flux Reticle 1.0.1
GraphicsLib 1.4.2
HullMods Expansion 4.2a (should be the latest version before the author asked it to be removed from the forums)
Hyperdrive 2.0.0
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Karlsson Heirloom 0.12
Lazylib 2.4f
Leading Pip 1.9.0
Logistics Notifications 1.3
Luddic Enhancement 1.2.2
MagicLib 0.29
Nexerelin 0.9.6e
Personal Adjustments (My own private mod which is basically just settings changes)
Player Gate Construction 1.1.1
Polaris Prime 0.23 RC-1
Secrets of the Frontier Prerelease 7
Shadowy Broker 0.1.5
Ship/Weapons Pack 1.11.0
SkilledUp 1.1
SpeedUp 0.6.1
Tahlan Shipworks 0.3.13
The Knights Templar 0.9.9b
Tiandong Heavy Industries 1.2.1a
Transfer All Items 1.1
Underworld 1.4.4
Vayra's Sector 3.1.5
Vesperion Combine 1.2.0
Weapons Group Controls 1.1.0
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on August 06, 2020, 09:24:22 PM
I can't find that on the log but I typed them out:

Spoiler
AI Core Production 1.0.0
Audio Plus 1.1.1x (old version which I modified to include other music)
Better Colonies 1.4
Commissioned Crews 1.9
Flux Reticle 1.0.1
GraphicsLib 1.4.2
HullMods Expansion 4.2a (should be the latest version before the author asked it to be removed from the forums)
Hyperdrive 2.0.0
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Karlsson Heirloom 0.12
Lazylib 2.4f
Leading Pip 1.9.0
Logistics Notifications 1.3
Luddic Enhancement 1.2.2
MagicLib 0.29
Nexerelin 0.9.6e
Personal Adjustments (My own private mod which is basically just settings changes)
Player Gate Construction 1.1.1
Polaris Prime 0.23 RC-1
Secrets of the Frontier Prerelease 7
Shadowy Broker 0.1.5
Ship/Weapons Pack 1.11.0
SkilledUp 1.1
SpeedUp 0.6.1
Tahlan Shipworks 0.3.13
The Knights Templar 0.9.9b
Tiandong Heavy Industries 1.2.1a
Transfer All Items 1.1
Underworld 1.4.4
Vayra's Sector 3.1.5
Vesperion Combine 1.2.0
Weapons Group Controls 1.1.0
[close]

FWIW, here's the intersection of my mod list, with your mod list (I too get horrific post battle slowdown)

Spoiler
Audio Plus 1.1.1x (old version which I modified to include other music)
GraphicsLib 1.4.2
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e
Ship/Weapons Pack 1.11.0
SpeedUp 0.6.1
Tahlan Shipworks 0.3.13
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: caekdaemon on August 07, 2020, 02:39:16 AM
For completion's sake, my mod list. The logfile didn't contain it for me either (is starsector.log the correct place for it?) so I just grabbed mine from enabled_mods.json

Spoiler
  "anvil_industries",
  "raccoonarms",
  "blackrock_driveyards",
  "Celestial Mount Circle",
  "CombatAnalytics",
  "timid_commissioned_hull_mods",
  "COPS",
  "lw_console",
  "diyplanets",
  "istl_dam",
  "diableavionics",
  "DisassembleReassemble",
  "XLU",
  "fluffships",
  "gt_galaxytigers",
  "ZGrand Sector",
  "GMDA",
  "HMI",
  "deconomics",
  "Imperium",
  "kadur_remnant",
  "lw_lazylib",
  "ArkLeg",
  "luddenhance",
  "MagicLib",
  "Mayasuran Navy",
  "metelson_release",
  "missingships",
  "nexerelin",
  "ORA",
  "roider",
  "SCY",
  "swp",
  "bonomel_skilledup",
  "sun_starship_legends",
  "StopGapMeasures",
  "Sylphon_RnD",
  "tahlan",
  "Terraforming and Station Construction",
  "THI",
  "TORCHSHIPS",
  "underworld",
  "US",
  "vayrasector",
  "vayrashippack",
  "lw_version_checker",
  "vesperon",
  "shaderLib"
[close]

Cross referencing my list with Cyan Leader's and Nick XR's gives these two lists:

Cyan Leader's List
Commissioned Crews 1.9
GraphicsLib 1.4.2
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Lazylib 2.4f
Luddic Enhancement 1.2.2
MagicLib 0.29
Nexerelin 0.9.6e
Ship/Weapons Pack 1.11.0
SkilledUp 1.1
Tahlan Shipworks 0.3.13
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]

Nick XR's list
GraphicsLib 1.4.2
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]

Then those two lists together equals this one, where only the mods that are in all three lists are:

Spoiler
GraphicsLib 1.4.2
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5[
[close]


Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Zoro89 on August 07, 2020, 06:26:05 AM
...
Then those two lists together equals this one, where only the mods that are in all three lists are:
...

I have the same issue. After 3-5 big battles (fleet points > 1000) the game run slowly immediatly when I'm on the galaxy map again. I have Ryzen 3600, 16 GB and RTX 2060S + Win 10 + SSD. I allocated 8 GB for the game.

This is our shared mod list after I compare it with the above one. On the next game run I will try to turn off Vayra's Sector because it's a "..."megamod" which changes, adds, or replaces several core campaign-level gameplay mechanics..."

Spoiler
GraphicsLib 1.4.2
Industrial.Evolution 1.7.d
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e / 0.9.6f
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13 / 0.3.17
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Cyan Leader on August 07, 2020, 06:36:58 AM
I'm curious in knowing if anyone that has been getting these slowdowns can report through the task manager if java is using more than 3G. I have a feeling that the game wants to use more memory but it can't for whatever reason, even when set to.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 07, 2020, 09:25:08 AM
Ah, yes, cross referencing mod lists.

Sadly, I am using all the ones listed myself. The remaining list is thus:
Spoiler
GraphicsLib 1.4.2
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e / 0.9.6f
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13 / 0.3.17
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]
At this point, I am leaning towards either Vayra or Nexelerin, which would coincide with the prior mentions of inventory interactions resulting in drops. The "big battles" usually end up with a big loot pile, and unless you skip the loot phase, would always end with opening your inventory. If you have positive experiences without Vayra, please let us know, Zoro89!

I'm curious in knowing if anyone that has been getting these slowdowns can report through the task manager if java is using more than 3G. I have a feeling that the game wants to use more memory but it can't for whatever reason, even when set to.
I've had Starsector at any number from 4GB to 7.8GB (when I had given it 8GB) of RAM. Sorry.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 08, 2020, 01:10:38 AM
And, an update. I played normally in my new playthrough, and I am still relatively small. No impacts to performance up until now, even when I forgot to go to bed last night. Just now, the very same behavior reoccurred.But that is not all. Just prior to this fight, I founded my first colony. This may be confirmation bias, but it seems that opening market dialogues takes longer now. If anything, this may just be because I've played for a while, and isn't really affecting gameplay all that negatively.

Peripheral data:More pointers towards Vayra's Sector? I just have no indication on what I could investigate further to confirm/rule out that it's Vayra's.

Any ideas on what to look for/how to look for the source of this?
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: pairedeciseaux on August 08, 2020, 02:34:51 AM
I just have no indication on what I could investigate further to confirm/rule out that it's Vayra's.

Any ideas on what to look for/how to look for the source of this?

Stupid yet important questions:

Other than that, plain binary search is your friend:

All of this is kind of sisyphean, having some forms of resource usage tracking built into Starsector could help pinpoint problems.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 08, 2020, 03:10:46 AM
The mod in question would be Vayra's Sector, which spawns these IBB bounty missions. The IBB in question does not seem particularly relevant, as this does track with previous events in retrospect; IBB missions of higher level are bigger battles, and it has not always been this specific IBB. I am led to believe that there's something off with Vayra's Sector.

The plain binary search is an option I'll go with next, and I'll simply disable the entire Vayra's Sector mod for it. After that, I'd escalate to Vayra and go from there.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Cyan Leader on August 08, 2020, 09:03:58 AM
It felt like my problems started after I founded my first colony as well.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 08, 2020, 09:30:50 AM
More pointers towards Vayra's Sector? I just have no indication on what I could investigate further to confirm/rule out that it's Vayra's.

Any ideas on what to look for/how to look for the source of this?

If the game starts going real slow - that is, if the frame dips are not periodic, but it's more consistent slowness - then I think the best thing to try would be to run jvisualvm, go to the "Threads" tab, and do a "Thread Dump".

What this does is give you a stack trace for the for all the threads in the current moment of the game. From the stack trace, you should be able to tell what the "main" thread is, and you can take a look to see what it's currently doing.

The thing is, though, since this is a snapshot of an instant in time, it may not be doing the thing that's causing the slowdown just then. But if it's something that is in fact slowing it down, then the odds of seeing it in the thread dump's stack trace are higher because whatever it is is taking more time than other things. Still, you'd want to do this a number of times to get a reasonable sample size - just one thread dump doesn't mean much since whatever it shows is effectively random. Weighted random, but still.

It might still not show the culprit. For example, if a mod were to add, I don't know, 1000 markets to the economy, then this would show the economy being slow without showing an indication as to why. But if there's some kind of script that's taking forever, or kicking off economy updates directly, or whatever, then you might be able to see it in the thread dump.

(And, actually, if it's spikes rather than general slowness, then this approach is probably worth a go, too. It'll just be trickier to time it right.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Volkssnake on August 08, 2020, 01:02:55 PM
The mod in question would be Vayra's Sector, which spawns these IBB bounty missions.

I would just like to chime in to point out the Vayra's Sector deals in High Value Bounties (HVB), Ship/Weapon pack is responsible for International Bounty Board (IBB).

I also experience massive post battle slow downs, particular when defending colonies, but this may just be a selection bias thing, I haven't really taken part in super massive battles outside of colony defense. I have 8gb allocated in vmparams.

And to eliminate a few more mods from the cross referenced list
Spoiler
GraphicsLib 1.4.2
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e / 0.9.6f
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13 / 0.3.17
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Wyvern on August 08, 2020, 06:23:32 PM
One possibly-new data point: I got the slowdown to trigger off of not-the-end-of-a-real-battle.  I'm not sure exactly what did it, though, as I was at my colony, tinkering around with variants, so there was a lot of swapping between inventory, fleet, and variant screens - plus a bunch of simulator battles.

(Next game I start I'll turn Vayra's Sector off, just to see if we can eliminate it from the list; my mods list otherwise includes everything in the latest shared batch.  I only run Vayra's Sector for its special bounty mechanics... and y'know, if I really want those unique hulls, I can always use console commands instead.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 08, 2020, 06:26:10 PM
Hmm - that might actually be a different issue. IIRC in vanilla there is (a now fixed) issue where it was possible for very large numbers of tooltips to accumulate in the interface without them being visible, and IIRC the refit screen (along with some specific circumstances) was involved here.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Wyvern on August 08, 2020, 06:59:03 PM
Possible!  Same symptom, though - an overall game slowdown that lasted until I restarted the game.  (...Okay, I'll admit, I didn't bother checking to see if the slowdown went away from just backing out to the main menu and then re-loading the save; I've gotten used to that not working.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 09, 2020, 12:54:17 AM
(https://i.imgur.com/jM5xPUR.png)

So... is this a leak?

Edit: 15 minutes later, letting it sit for a while, GC seems to have cleaned up some, but not all of them. Performance has recovered from 1 FPS to ~8FPS. At this time Starsector us using 5.6GB out of 7GB assigned.

(https://i.imgur.com/pZoF4AL.png)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on August 09, 2020, 09:26:36 AM
Great work.

Now you just need to determine what is still rooting those objects.  If you have a heap dump I'd happily take a look at it for you.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 09, 2020, 09:37:20 AM
Ah - this is not a leak, though I can see how that could look like one. What you're looking for is the number of instances of "CampaignEngine", exactly - and of those, your screenshots show only one.

CampaignEngine$1, CampaignEngine$2, CampaignEngine$3 etc are different classes - that's how Java names anonymous classes inlined within another class. It's totally fine to have multiple instances of these and does not indicate a memory leak or any other problem. Offhand, the animation for a fleet transitioning to hyperspace is one of these, etc - it's various minor things. So basically, despite the name similarity, these are a completely different thing.


Edit: 15 minutes later, letting it sit for a while, GC seems to have cleaned up some, but not all of them. Performance has recovered from 1 FPS to ~8FPS. At this time Starsector us using 5.6GB out of 7GB assigned.

Hmm, I'd really recommend trying the thread dumps. It looks more and more like a different sort of problem - where it's not leaking a CampaignEngine instance, but instead creating a bunch of... something. Probably some kind of script that gets added many times instead of once and tanks performance.

As far as the 5.6 gb usage - is this the number from jvisualvm in the "Monitor" tab (preferably after pressing the "Perform GC" button there, to get the true memory use), or from task manager? The task manager numbers can be very unreliable and I wouldn't want to draw any conclusions based on that.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 09, 2020, 10:14:39 AM
5.6GB came from task manager. Nevermind that number then!

I did save my dumps, just in case someone was curious, and also because navigating the Thread dump or finding the GC root has been largely elusive to me. I don't know enough to execute Alex' instructions, since VisualVM seemingly has slightly different menu structure.Maybe one of y'all can interpret these dumps. :(
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 09, 2020, 10:29:14 AM
Looking at the thread dump:

Code
"Thread-4" prio=6 tid=0x0000000019fa8800 nid=0x59cc runnable [0x000000001a87e000]
   java.lang.Thread.State: RUNNABLE
at com.fs.starfarer.settings.StarfarerSettings$1.getCommoditySpec(Unknown Source)
at com.fs.starfarer.campaign.Faction.isIllegal(Unknown Source)
at com.fs.starfarer.campaign.econ.Market.isIllegal(Unknown Source)
at exerelin.campaign.intel.missions.Nex_ProcurementMissionIntel.pickMarket(Nex_ProcurementMissionIntel.java:82)
at com.fs.starfarer.api.impl.campaign.intel.ProcurementMissionIntel.<init>(ProcurementMissionIntel.java:81)
at exerelin.campaign.intel.missions.Nex_ProcurementMissionIntel.<init>(Nex_ProcurementMissionIntel.java:24)
at exerelin.campaign.intel.missions.Nex_ProcurementMissionCreator.createMissionIntel(Nex_ProcurementMissionCreator.java:10)
at com.fs.starfarer.api.impl.campaign.intel.GenericMissionManager.createEvent(GenericMissionManager.java:132)
at com.fs.starfarer.api.impl.campaign.intel.BaseEventManager.advance(BaseEventManager.java:141)
at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
at com.fs.starfarer.campaign.CampaignState.advance(Unknown Source)
at com.fs.starfarer.BaseGameState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Looks like what the game was currently doing is trying to generate a Nex procurement mission - Nex_ProcurementMissionIntel. But, per what I was saying earlier, it's just a snapshot in time - if, say, we had 10 or 20 of these, and half of those show the game doing that, then that would be an indicator that this specific thing is taking a long time to do, since a bunch of random samples all showed it as the "thing currently being done", if that makes sense.

But it being a single snapshot... I mean, it's in some sense an indicator that there might be a problem there, but it's also just one roll of the dice.

As far as generating a thread dump - hmm, looked at some instructions for Visual VM (which is what you have, right?) here:
https://www.infoworld.com/article/2072865/thread-analysis-with-visualvm.html

The relevant thing seems to be:
Quote from: infoworld
The first way to do this is to right-click on the appropriate Java process and select the option "Thread Dump." This will generate a thread dump file whose name appears under the selected Java process as shown in the following screen snapshot.

Another thing you could try is start the CPU sampler in visualvm. I'm not sure exactly what the steps would be for visual vm specifically, but for jvisualvm there's a "sampler" tab where you can press a "CPU" button to begin sampling. It's a more efficient (but probably a bit harder to interpret?) way of doing the same thing, basically. It'll show which methods are taking up the most CPU time by doing sampling (rather than full-on profiling, which is more exact in some circumstances but also bogs the application down by a factor of 10 or more).
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on August 09, 2020, 12:31:47 PM
Another thing you could try is start the CPU sampler in visualvm. I'm not sure exactly what the steps would be for visual vm specifically, but for jvisualvm there's a "sampler" tab where you can press a "CPU" button to begin sampling. It's a more efficient (but probably a bit harder to interpret?) way of doing the same thing, basically. It'll show which methods are taking up the most CPU time by doing sampling (rather than full-on profiling, which is more exact in some circumstances but also bogs the application down by a factor of 10 or more).

FWIW I've tried that whith this issue and any of the high-accuracy options would effectively crash my computer and the low accuracy stuff just pointed to the general game event loop that already has developer instrumentation with a bunch of noise. 

I know this will sound low-tech, but just getting a bunch of stack dumps via CTRL-BREAK (or from visualvm ) and looking at what stuff comes up frequently has worked for me at least 90% of the time historically.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Wyvern on August 09, 2020, 08:26:13 PM
So, I have, one, reproduced this issue with Vayra's Sector disabled.

And, two, gotten jvisualvm sampling working.  Unfortunately, it didn't immediately tell me where the problem is; according to sampling, about 50% of the time is going to sound.H$2.run... but further testing shows that that's entirely normal and not symptomatic of performance issues.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 09, 2020, 08:35:57 PM
Just, worth noting again that your issue could very well be a different one! This time around, did you also spend a bunch of time in refit?

How long did you spend sampling, btw? I woudn't expect  sound.H$2.run to take much time, that's kind of odd - it's the music player which is on a different thread and spends much of its time sleeping. Turning in-game music off should remove it from the picture.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Wyvern on August 09, 2020, 08:41:54 PM
This time was the classic after-a-battle slowdown, not whatever-it-was I reported earlier.  (I mean, okay, -some- time spent in refit, since I basically started a new game and then ran with that until I had problems, but nothing really excessive, and that's not when I started seeing performance issues.)

From what you mentioned, I think the sound.H$2.run thing is just because it is multithreaded - it's spending a lot of time there just because it's in a different thread and there's nothing competing for that CPU.  Good tip on how to turn it off, though; that should make it easier to look through everything else.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 09, 2020, 08:44:10 PM
Ah, gotcha, thank you for elaborating - this does sound more like the same issue, then. And, yeah, you're probably right about it being a % of that one thread, that makes sense.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Wyvern on August 10, 2020, 12:39:50 AM
Still not definitive, but here's some more data:

Baseline, flying around with no slowdown, I see:
54% of time is in com.fs.starfarer.campaign.CampaignEngine.advance()
35% of time is in org.lwjgl.opengl.Display.update()
7.5% of time is in com.fs.starfarer.campaign.CampaignState.render()

With slowdown, the breakdown is instead:
54% CampaignEngine.advance()
25% Display.update()
14% CampaignState.render()

Hm.  Looks like there's something suspicious under CampaignState.render().  Let's break that down another level.

Baseline, no slowdown:
com.fs.starfarer.campaign.CampaignEngine.render(): 3.2%
com.fs.starfarer.ui.interface.render: 3%
and a few other smaller things make it all round up to 7.5% total for CampaignState.render.

With slowdown:
com.fs.starfarer.ui.interface.render: 8.6%

...Okay, so it looks like whatever the problem is, it's something to do with UI rendering?  (Trying to track the stack traces down further did not, unfortunately, yield any further information or any sort of obvious smoking gun.)

This was, again, a slowdown triggered after end of battle.  Though, with your comment on invisible tooltips hanging around, I'm wondering if there's a way for such a thing to be generated by an end-of-battle collection screen or something?  Looks like I may need to do memory sampling in addition to CPU sampling...  but not tonight.   This morning?  Whichever; I need to get some sleep.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Cyan Leader on August 10, 2020, 04:21:14 AM
I get a lot of slowdowns after a certain point of the game just by going to markets. Hell, even surveying planets take like a 3 seconds longer than usual. While the big battle one also happens, it's not the only source of the problem I feel.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: RartyMobbins on August 10, 2020, 06:07:25 AM
Registered just to say I have the same problem in my current playthrough. My mod list is quite large but the mods that I suspect might be the source of the issue are Vayra's Sector, Nexerelin and, to a minor degree, Adjusted Sector.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on August 10, 2020, 09:16:55 AM
Spoiler
Still not definitive, but here's some more data:

Baseline, flying around with no slowdown, I see:
54% of time is in com.fs.starfarer.campaign.CampaignEngine.advance()
35% of time is in org.lwjgl.opengl.Display.update()
7.5% of time is in com.fs.starfarer.campaign.CampaignState.render()

With slowdown, the breakdown is instead:
54% CampaignEngine.advance()
25% Display.update()
14% CampaignState.render()

Hm.  Looks like there's something suspicious under CampaignState.render().  Let's break that down another level.

Baseline, no slowdown:
com.fs.starfarer.campaign.CampaignEngine.render(): 3.2%
com.fs.starfarer.ui.interface.render: 3%
and a few other smaller things make it all round up to 7.5% total for CampaignState.render.

With slowdown:
com.fs.starfarer.ui.interface.render: 8.6%

...Okay, so it looks like whatever the problem is, it's something to do with UI rendering?  (Trying to track the stack traces down further did not, unfortunately, yield any further information or any sort of obvious smoking gun.)

This was, again, a slowdown triggered after end of battle.  Though, with your comment on invisible tooltips hanging around, I'm wondering if there's a way for such a thing to be generated by an end-of-battle collection screen or something?  Looks like I may need to do memory sampling in addition to CPU sampling...  but not tonight.   This morning?  Whichever; I need to get some sleep.
[close]

First off, thank you for doing this! Hmm.

This actually doesn't seem right. A couple percent difference in the time spent rendering is not going to affect the framerate in a way that's even detectable, let alone bring it down that much. The time spent in Display.update() is mostly time spent sleeping waiting for vsync. The time change spent in render() is probably due to a relatively different amount of time spent waiting for vsync() due to the advance() method taking longer than a single frame's time and changing how all that lines up.

Besides, even with the slowdown, you're looking at rendering being by far the smallest of these three. The data doesn't make too much sense, though, but I'm pretty positive that what it doesn't point to is a UI issue. To me this just looks... strange, like some pieces of the puzzle are missing, or the sampler didn't run long enough, the game was paused/inactive while sampling, the sampling itself affected the distribution (that's always fun), or *something*. Basically, I'd expect to see something more pronounced given the conditions under which the samples were taken, and it's not there, so we're missing something.

Also, the tooltips issue wouldn't just happen like you're thinking - it'd take some time, and iirc was refit-specific. It's basically a red herring for 99% of the cases, not something many people would run into or be noticeably affected if they did.

It'd be interesting to see the data from a screenshot of jvisualvm/visualvm, if you have that. Some thread dumps would I think also be informative.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Wyvern on August 10, 2020, 10:35:56 AM
Hm.  Fair enough; it is only two data points, and inexpertly interpreted at that.  I'll see what I can come up with the next time I run into the problem.  (Annoying that it takes so long to reproduce.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 10, 2020, 12:47:23 PM
I've been trying hard, but after 300 minutes / 30 battles / 50 market interactions, I still had no return of the slowdown.

Which is the darndest thing, because you'd think something that pops after "one big battle" would have popped in that time. "One big battle" in this case was three fleets in one, which was a slog, but, ultimately won.

I did reduce my battle size from 500 to 400 intermittently, though. Maybe that helps? Maybe that averts it from reoccurring? Show of hands, what's your battle sizes?
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Histidine on August 10, 2020, 05:14:52 PM
500, have after-battle slowdowns

(Having the issue without Vayra's Sector. Skimming thread dumps hasn't shown anything interesting.
I'm fairly confident it's not a RAM issue; console mod's RAM display doesn't show memory use exceeding 2 GB of the 5 GB I have allocated at any point.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Ced Riggs on August 13, 2020, 05:18:40 AM
During the forum maintenance, I managed to reproduce the issue with 400 battle size, so that's not a safeguard. What I saw in thread dumps was 20% of CPU time alloted to CampaignState.advance and 15% Econ.advance (sp?) over about an hour after first experiencing the slowdown. Turning off campaign map "speed-up" smoothed my FPS experience, but still ran noticeably slower than before that "big battle" event. This time, with Vayra's off, it wasn't an HVB, and it wasn't an IBB - just a regular "Personal Bounty" and a Vengeance Fleet.

Trying to bore down onto the higher rated advance elements did not yield anything I could understand or associate with anything in particular.

Edit: Here's the saved snapshot (https://www.ced23ric.de/starsector/snapshot-1597322437132.nps).

Edit²: After 3h, 30 battles, and a excruciatingly slow campaign map traverse with slow menus...

(https://i.imgur.com/D9tHJiv.png)

... I now have 3 hours of CPU sampling, and these are my "hotspots":

(https://i.imgur.com/w0EH1m9.png)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Pokpaul on August 16, 2020, 12:47:05 PM
Probably unrelated, but does anyone else have issues with Starsector sometimes randomly taking a really long time to load and then running like crap? Basically when this happens I restart my computer and then it works normally, although once I had to restart twice for it to go.

Nothing to do with saves, just when starting up Starsector. I'm not changing anything to do with mods or anything, just loading up the same mods every time. I've had visual vm and resource monitor running when this happens, and I'm not even seeing any elevated use of memory, CPU or hard drive, it's just slow.

Normally it takes Starsector about 30 sec to load for me. Then randomly it sometimes takes minutes, for no obvious reason. Sometimes it happens if Starsector is the first thing I do when I start the computer, sometimes it happens if I've been working on something all day and then load up Starsector. I'm not running things in the background or concurently either.

Even though I've got no issues with anything else I run, I've checked my system for the usual suspects and not found anything.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Pokpaul on August 24, 2020, 06:13:15 PM
I'm finding that the game slowdowns and errors are coming and going as I progress, for reasons I can't understand.

For example, my save sizes grow and shrink. My last five saves, most recent first, were 65, 75, 63, 63, 126 MB. The larger saves were associated with greatest in-game and saving slowdowns.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: caekdaemon on August 25, 2020, 04:03:07 AM
I did reduce my battle size from 500 to 400 intermittently, though. Maybe that helps? Maybe that averts it from reoccurring? Show of hands, what's your battle sizes?
2000. I did a little tweak because I wanted bigger battles with more stuff going on, but I get the problem even with small battles of 500-points and just had it again in a whole new save with completely updated mods and loads of other stuff going on. Ended with a fleet wipe, but when I respawned, pure stutter.

EDIT: I just had a thought: has anyone tried to reproduce this bug in the simulator, seeing if a gigantic battle in there causes the slowdown when exiting the screen?
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Kawira on September 20, 2020, 05:10:39 AM
I also have this problem. What I've noticed is that it's not happening until one random moment then you can play 2-3 big battles before occurs again. At one point my game refused to save at last playthrough. Sounds like whatever it is doing, it's slowly corrupting saves.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Zoro89 on September 29, 2020, 12:11:56 AM
@ Kawira
The same happened to me too. I can "fix" this if I exit the game to desktop and reload a save game before the battle. 2-5 big battles are possible before it happened again. So after the second battle save, exit and load again.

According to our previous shared modlist I can confirm: It's not Vayra's Sector or GraphicLibs.

Spoiler
GraphicsLib 1.4.2 with enableShaders=false
Interstellar Imperium 2.2.1
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.6e / 0.9.6f 0.9.7b
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13 / 0.3.17
Tiandong Heavy Industries 1.2.1a
Underworld 1.4.4
Vayra's Sector 3.1.5
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Histidine on September 29, 2020, 07:51:13 PM
Wacky thing to attempt: Does using Java 8 make the issue go away, or at least delay it?
I did this and haven't been able to readily reproduce the issue after a series of battles; campaign FPS with Shift speedup doesn't reliably go below 57, whereas before it'd IIRC drop to 20 or so.

To try this:
- Install newest Java (version 8 update 261) from Oracle site (https://www.java.com/en/download/)
- In [starsector-core]/data/config/settings.json, set allowAnyJavaVersion to true
- Change vmparams or the starsector .bat (depending on how you start Starsector) to begin with "java" instead of "..\jre\bin\java.exe"

(Starsector's update to Java 8 was originally reverted and the use of non-standard versions blocked because it caused some strange bugs that couldn't be feasibly tracked down in the available time, but one hopes the newest version doesn't have these issues)
(Also wondering if the newest update of Java 7 works)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on September 29, 2020, 08:15:46 PM
(IIRC one of - not the only, there was some weird hard crashing, too - the issues with 8 is that its GC settings are by default different and can cause actual frame drops especially with larger allocations. There's, again iirc, some set of JVM parameters that could be added to use the default Java 7 GC behavior.)
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Histidine on October 07, 2020, 07:31:57 AM
Back on Java 7 (for testing purposes): I was able to reproduce in my game without Nexerelin or Tahlan, albeit with a significant number of other mods and I had to spawn + nuke a bunch of fleets with console to get a really noticeable effect.

It also readily occurs in my previous game without SWP.

Profiling continues to turn up nothing of interest, and console still indicates memory use is a fraction of the available amount. The thing that used up the most RAM according to JProfiler was Vector2f (which can approach 500 MB prior to GC), but this happens even after an application restart (i.e. no lag yet). ArrayLists are another significant hog.

Common mod list
Lazylib 2.4f
MagicLib 0.29
Nexerelin 0.9.7b
Ship/Weapons Pack 1.11.0
Tahlan Shipworks 0.3.13 / 0.3.17
[close]

I have the inkling that the slowdown stems from some unknown issue in the JVM.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Modo44 on October 07, 2020, 10:59:11 PM
I can add that Alt-Tabbing brings the slowdowns on quicker using either Java version. This happens both in full screen (for UI scaling), and windowed (for watching streams on the side) modes. Running dozens of mods.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: SaberCherry on October 09, 2020, 09:35:10 PM
I'm not sure how relevant this is, but the one time I had a massive permanent slowdown - which was solved by saving (which took a long time), exiting, and reloading - was when I put a whole bunch of stuff into storage.  The game was fine; I pushed a bunch of stuff into storage, and while doing that, it got extremely sluggish...  and never recovered.  Since people mention this sometimes happening after a big battle or visiting a colony, I wonder if inventory management could be involved.

This was a modded game with Nexerelin and various others...  specifically:

{"enabledMods": [
  "raccoonarms",
  "automatic-orders",
  "lw_autosave",
  "alportraitpack",
  "alibportraitpack",
  "alrnportraitpack",
  "blackrock_driveyards",
  "CombatAnalytics",
  "DisassembleReassemble",
  "Imperium",
  "lw_lazylib",
  "ArkLeg",
  "luddenhance",
  "MagicLib",
  "nexerelin",
  "ORA",
  "TAR",
  "SCY",
  "shadow_ships",
  "swp",
  "speedUp",
  "Sylphon_RnD",
  "THI",
  "transfer_all_items",
  "US",
  "lw_version_checker",
  "yrxp",
  "shaderLib",
  "prv"
]}
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Jaghaimo on October 19, 2020, 02:17:01 AM
Profiling continues to turn up nothing of interest, and console still indicates memory use is a fraction of the available amount.

...

I have the inkling that the slowdown stems from some unknown issue in the JVM.
Did you look at the distribution of free space inside heap space? We might be fine in eden and survivor space but running out of tenured space (or worse - permanent space).
My bet would be on Stop The World event caused by GC when it runs a major collection on tenured space.
(IIRC one of - not the only, there was some weird hard crashing, too - the issues with 8 is that its GC settings are by default different and can cause actual frame drops especially with larger allocations. There's, again iirc, some set of JVM parameters that could be added to use the default Java 7 GC behavior.)
Java7 uses serial collection, while Java8 uses parallel (serial if you use 32bit or single CPU machine). Neither seems good for heavily modded game with large heap sizes. Perhaps we should try running with G1 instead, as that's optimal for large memory (5-6G or larger) and low pause time (0.5s or less)?

https://www.oracle.com/technical-resources/articles/java/g1gc.html
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: HySOqvs0sB8 on October 19, 2020, 11:56:09 AM
...

The game uses parallelGC by default, but the algorithm does not even matter here. I would expect the users to get an OOM error instead of gradually degrading FPS if the issue is memory related.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: pairedeciseaux on October 19, 2020, 06:51:16 PM
Back on Java 7 (for testing purposes): I was able to reproduce in my game without Nexerelin or Tahlan, albeit with a significant number of other mods and I had to spawn + nuke a bunch of fleets with console to get a really noticeable effect.

Just to clarify,

You manually spawned one fleet using console, then fought the fleet. Then went to a market to repair own fleet? Then performed a number repetitions of the cycle? How many repetitions? Anything else? What was the approximate size of both fleets?

Would you consider that to be a proper reproducible test case at this point?

If yes, next steps could be: reproduce with vanilla-only, reproduce with small battles (if at all possible), have other people reproduce the slowdown given a simplified test case, pray profiling will show something.

The game uses parallelGC by default, but the algorithm does not even matter here. I would expect the users to get an OOM error instead of gradually degrading FPS if the issue is memory related.

If a significant amount of time is spent in GC, then GC tuning should be tried, no? I don't know, think fragmentation rather than leak, too much GC work to do, or other nasty JVM memory management behaviours.

Hmmm, I wonder whether tuning GC is a waste of time compared to things like: improving code in vanilla and mods when bottlenecks are identified, or, I guess, reducing game scope and scale ... but at the same time, my understanding is that no clear bottleneck has been found yet.

Does/can profiling used so far in this thread show unusual GC activity? It may not be relevant at all, but I'll mention it anyway: has anyone tried something like the following and checked the output log file?

Code
-Xloggc:../../../logs/gc.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

I have run with theses options less than 30 seconds using an end-game vanilla save, simply moving own fleet from a system to hyperspace and gave a quick look at the output, see below. And to be clear, I did not try to reproduce the post-battle slowdowns discussed above, I am annoyed by unstable FPS both in-system and in hyperspace. Also please note I am not a Java person, at all.

Spoiler
Java HotSpot(TM) 64-Bit Server VM (24.79-b02) for bsd-amd64 JRE (1.7.0_79-b15), built on Apr 10 2015 11:35:04 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Memory: 4k page, physical 41943040k(10485760k free)

/proc/meminfo:

CommandLine flags: -XX:+CompilerThreadHintNoPreempt -XX:CompilerThreadPriority=1 -XX:InitialHeapSize=4294967296 -XX:MaxHeapSize=4294967296 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:ThreadStackSize=1024 -XX:+UseCompressedOops -XX:+UseParallelGC
4.988: [GC [PSYoungGen: 1049088K->25132K(1223680K)] 1049088K->25140K(4020224K), 0.0152840 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
7.505: [GC [PSYoungGen: 1074220K->81428K(1223680K)] 1074228K->81444K(4020224K), 0.0246230 secs] [Times: user=0.06 sys=0.03, real=0.02 secs]
10.627: [GC [PSYoungGen: 1130516K->164463K(1223680K)] 1131556K->165512K(4020224K), 0.0387260 secs] [Times: user=0.10 sys=0.05, real=0.04 secs]
12.305: [GC [PSYoungGen: 1213551K->78796K(1223680K)] 1218598K->83850K(4020224K), 0.0165760 secs] [Times: user=0.05 sys=0.00, real=0.02 secs]
13.447: [GC [PSYoungGen: 1127884K->50199K(1223680K)] 1132957K->55272K(4020224K), 0.0181630 secs] [Times: user=0.06 sys=0.00, real=0.02 secs]
19.294: [GC [PSYoungGen: 770431K->48056K(1240064K)] 775504K->53138K(4036608K), 0.0178920 secs] [Times: user=0.06 sys=0.00, real=0.02 secs]
19.312: [Full GC [PSYoungGen: 48056K->0K(1240064K)] [ParOldGen: 5081K->47048K(2796544K)] 53138K->47048K(4036608K) [PSPermGen: 25959K->25947K(52224K)], 0.1210730 secs] [Times: user=0.32 sys=0.01, real=0.12 secs]
22.974: [GC [PSYoungGen: 740456K->158181K(1207296K)] 787504K->237282K(4003840K), 0.0741000 secs] [Times: user=0.25 sys=0.02, real=0.07 secs]
23.048: [Full GC [PSYoungGen: 158181K->0K(1207296K)] [ParOldGen: 79100K->230314K(2796544K)] 237282K->230314K(4003840K) [PSPermGen: 32165K->32160K(63488K)], 0.3614440 secs] [Times: user=1.28 sys=0.03, real=0.36 secs]
Heap
 PSYoungGen      total 1207296K, used 646689K [0x00000007aaa80000, 0x0000000800000000, 0x0000000800000000)
  eden space 1049088K, 61% used [0x00000007aaa80000,0x00000007d2208708,0x00000007eab00000)
  from space 158208K, 0% used [0x00000007ec580000,0x00000007ec580000,0x00000007f6000000)
  to   space 163840K, 0% used [0x00000007f6000000,0x00000007f6000000,0x0000000800000000)
 ParOldGen       total 2796544K, used 230314K [0x00000006fff80000, 0x00000007aaa80000, 0x00000007aaa80000)
  object space 2796544K, 8% used [0x00000006fff80000,0x000000070e06a880,0x00000007aaa80000)
 PSPermGen       total 63488K, used 34326K [0x00000006fad80000, 0x00000006feb80000, 0x00000006fff80000)
  object space 63488K, 54% used [0x00000006fad80000,0x00000006fcf05ac8,0x00000006feb80000)
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Histidine on October 20, 2020, 03:59:33 AM
Back on Java 7 (for testing purposes): I was able to reproduce in my game without Nexerelin or Tahlan, albeit with a significant number of other mods and I had to spawn + nuke a bunch of fleets with console to get a really noticeable effect.

Just to clarify,

You manually spawned one fleet using console, then fought the fleet. Then went to a market to repair own fleet? Then performed a number repetitions of the cycle? How many repetitions? Anything else? What was the approximate size of both fleets?

Would you consider that to be a proper reproducible test case at this point?
I only tried it once, and don't really recall the sequence of events. There was no attempt at creating a reproducible test case, although I could try doing so using the save.

I think it was something like

Spawn fleet -> nuke -> do not return to a market -> spawn a new fleet and repeat

I think this came after one or more real battles, and I also did stuff like fly in hyperspace in an attempt to lower the framerate.
Spawnfleet command was used with (IIRC) 200 FP parameter. I think the actual fleets created by the command are larger than this.

@Jaghaimo: Given that I didn't understand any of that, this is probably my limit in terms of attempting to generate a hypothesis on the cause of the issue :-X
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: pairedeciseaux on October 20, 2020, 03:22:24 PM
Ok, running the spawnfleet and nuke commands was pretty easy. I tried both in a new vanilla campaign, and in my vanilla end-game save. I didn't obtain any permanent slowdown.

FYI here are launch count for commands I used in the new campaign, and of course I encountered all existing and naturally spawning Hegemony military fleets in Jangala + some pirates.

   1 spawnfleet tritachyon 50
   1 spawnfleet hegemony 100
  11 spawnfleet hegemony 200
  89 nuke


(depending on fleet size, between 1 and 3 nukes were necessary to defeat the fleet)

Maybe there wasn't enough battles. Or it can't be reproduced with vanilla-only. Or I don't know.

Please note my testing setup was different than my regular gaming setup. When I play the game, I use fullscreen 2560x1440 + sound. While testing this, I used windowed 1920x1080 + no sound. This is a LCD-type display with a 60 Hz refresh rate. Also I almost always use fully zoomed-out view. And I almost always use speed time mode.

That said,

I've made a few interesting observations looking at the fleet activity (and debris) + FPS + idle + CPU usage. Interesting to me, as these are probably obvious to people understanding the game's inner workings.

(I also quickly looked at GPU usage but didn't notice anything, Starsector only use a somewhat constant 50%)

CPU is a 7600K, so 4 cores at 3.8 GHz. Basically Starsector does most of its work on a single core, the percentages indicated below are single-core usage, unless I am badly mistaken.

Whether in a system or in hyperspace, there is a baseline CPU usage. In the new campaign, I had 30% inside Jangala system near the jump point, around 50% in hyperspace near the jump point, and around 60% near Askonia.

That CPU usage increases as fleets and debris are displayed. I got around +5% CPU usage per large fleet. And +10% more if mouse-over a fleet. This +5% increase per fleet seem really high.

So I guess the bigger the screen resolution, the bigger the number of potential displayed fleets and other objects, leading to higher CPU usage. Right? I haven't tried to isolate hyperspace storms CPU usage, but I guess these are kind of objects too and each have some CPU cost.

So I used batches of "spawnfleet player 200" and watched the result. This way I obtained easily reproducible "slowdowns". My understanding of what happened is:

Now maybe I should not call these slowdowns, and I can't tell whether / how many people in this thread witnessed the same thing. I saw FPS instability. In the testing conditions, were the player fleet was static and the view stayed static too, it was only mildly annoying seeing the jerky fleet movements. But it is precisely this phenomenon that becomes very annoying once player fleet is moving and there is tons of objects and background display: you don't get a smooth scrolling anymore. Which definitely is something you want to avoid in a 2D game with a lot of scrolling, IMO.

Does the game also use an explicit 45 FPS goal or do you only encounter that when the game transition from 30 to 60, and from 60 to 30?

It seems the game is over-eager to go back to 60, and I suspect in many situations it only leads to bouncing back and forth from 30 to 60 to 30 to 60 ... with all the ugly intermediate FPS and non-smooth scrolling.

If this analysis is correct, I guess the right thing to do is:

If possible, reduce CPU cost to display a fleet?

Another thing to consider would be to implement a "level of detail" thing (as LOD in 3D applications with large scene and a lot of objects) where basically the game would only display the detailed fleet (each ship with its own engine trail) when zoomed-in (=pretty mode), and would display a simplified fleet (one ship or one abstract icon with a single trail) when zoomed-out (=performance mode). You get the idea.

Last minute tests: I checked and obtained the same behaviour fullscreen 2560x1440 with sound, also when turning off the speed time mode the problem is less likely to appear (I guess if game runs slower then it uses less CPU, so more CPU is available to handle peak load such as high number of fleets/objects to display). Which means there currently is two performance leverages: (1) use lower resolution in order to reduce the number of potential displayed objects (less CPU usage), (2) do not enable speed mode in order to "increase available CPU".
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on October 20, 2020, 03:29:44 PM
Hmm - what you're describing is just normal "too much stuff on the screen" behavior, not any sort of bug or issue that can (or indeed needs to) be resolved.

Basically, past a certain number of things the game has to render, it won't be able to do it at 60 fps (this holds regardless of optimization; that point just comes later then), and so it'll drop to a lower frame rate. Since vsync is on, framerates lower than 60 will be numbers that divide evenly into 60 - so, 30, 20, 15, 12, 10, etc. Intermediate numbers are caused by the framerate changing from one of those numbers to the other, since the fps counter shows the average framerate for the last second.

The game will increase the timestep as the framerate drops - up to double at 30 fps - so there shouldn't be any slowdown until the game drops below 30.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: pairedeciseaux on October 21, 2020, 12:46:15 AM
Hmm, sure one can't expect an infinite number of stuff rendered on screen smoothly.  :)

I am nonetheless surprised by the high CPU cost to render a single 200 FP fleet. Basically one could run several concurrent old classic 2D games (think shmups and run&guns with tons of bullets) or even old software rendered 3D games within that CPU budget (around a 150 MHz Pentium Pro), ... granted, at a lower resolution and lower color depth.

On my computer, ten 200 FP fleets displayed together is already too much in some areas. Whether that is acceptable or not is your call given intendended game scale and recommended computer specs.

I quickly tried with vsync OFF, and FPS was around 50; whereas with vsync ON FPS "goal" was jumping back and forth from 60 to 30 to 60, giving a similar choppy experience unless I am mistaken. One of the things I meant in previous message, maybe poorly phrased, is that experience with vsync ON would be smoother if the game stayed at 30 longer rather than instantly jumping back to 60. FPS instability is the main issue AFAIC, regardless of optimisations.

I suspect some players using tons of faction mods are experiencing these "FPS drops" because of the "high" number of displayed fleets (and possibly debris). I agree this is not a bug, more like an issue about pushing game scale + keeping a smooth rendering. Though I do wonder how this translates on slower computers with just the vanilla game in busy areas such as Askonia.

edit: fixed typo and added "smoothly" to first sentence
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Modo44 on October 21, 2020, 01:04:51 AM
It's not the rendering that is costly, it's calculating all the object interactions. Sure it can be "optimized" by various hacks that calculate less, and emulate complexity with purty graphics, but that is not at the core of Starsector.

Have you noticed that most games only let you control battles in turns, or use very generalized control that only seems to affect every detail (e.g. you control the flags, not individual fighters in the Total War series). Now you know why.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Alex on October 21, 2020, 09:37:34 AM
Ah, my main point is that this looks like a completely separate issue from what's discussed in the thread.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: pairedeciseaux on October 21, 2020, 11:13:13 AM
It's not the rendering that is costly, it's calculating all the object interactions.

I'm not 100% sure, but it really looks like slow rendering: no fleet on sight = 40% CPU, large fleet enters screen = 45% CPU, large fleet leaves screen = back to 40% CPU.

If the cost of "calculating all the object interactions" were that high for each fleet, the game would be unplayable.

Ah, my main point is that this looks like a completely separate issue from what's discussed in the thread.

Fair enough. I came to this from a vaguely-related-consequences point of view (FPS drops) and wasn't sure whether to post here or elsewhere. Feel free to move or delete those messages.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Lance on October 27, 2020, 10:13:33 AM
Hello, i registered to say that i have/had the same problem.

After hours of simulations & tests in the -REFIT- screen of the ships, with different weapons and ships, the game was slowd permanently, even without playing the campain, doing real fights or touching the command screen.


It somehow got better when i removed Speedup Mod and put the combat speed at *2 in the game settings instead. The game ran way better after a lot of fights, be it simulated or not.  Maybe static bloat?  anyway, i'm sure that speed up was the main culprit for this specific problem.


 Another thing that slows the game drastically is the amount of weapons. Or something tied to it:

Thoses weapons, in your home's storage, could slow the game whenever a techmined item is added, and whenever we access the command panel? Nowaday i send the techmined items on another planet than my home and it seems better...  (i mean, my official storage is not my home, more accurate) but it could simply be pure luck... Note, i'm talking about 5000++ weapons and atleast 100+ different ones. ( not 5000*vulcan cannon but 100 units of vulcan/devastator/markix/..... etc)

a third thing that slows the performances massively, it's the stations in hyperspace, with patrol hq/command center, they can be added by tahlan and vayra sector

Also, vayra sector, on a huge modded game, reduces my fps from 60 to 45 in campaign with a FRESH & new game. So i believe it is the main culprit for bad performances. It's a shame because HVB are amazing...
for java 8, it stutters a bit more and average fps is a bit worse...  i dunno about the long term performance
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Drglord on December 16, 2020, 09:52:21 AM
I'm curious in knowing if anyone that has been getting these slowdowns can report through the task manager if java is using more than 3G. I have a feeling that the game wants to use more memory but it can't for whatever reason, even when set to.

My version uses up to 7GB of memory i have 8192 allocated. CPU usage is 12% and graphic maxes out in 50%. There is definetely something slowing it down but it is difficult to track down with so many mods.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Drglord on December 16, 2020, 10:07:19 AM
I think the space stations of legio infenalis drop down the perfomance ALOT that are in hyperspace. I have noticed when you are in a area with one a massive slow down occurs.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Flacman3000 on January 02, 2021, 05:07:11 PM
did anyone find a solution to this situation so many memory leaks but I have all the mods we narrowed down for the sake of improved enjoyment. It's sad and unfortunate is there a way to change the java that's running the game id like to try java 8 but I don't know how I cant see what java to replace in star sector core or what to do in vmparam.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Flacman3000 on January 03, 2021, 04:33:09 AM
Maybe Magiclib is the culprit, I mean it deals with community scripts that might be prone to memory leak issues abroad I'm finding my game unplayable now seems the more time I spend on one save the faster it gets slower after big battles even though the UI is perfectly fine I can reach a saving time of 1 minute sometimes lmao on an SSD! I even reduced my map size to vanilla still happening I'm about to cry it's my favourite game.
I hope my donations go well but I really can't enjoy the game without the mods. lowkey depressed.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: SirHartley on January 03, 2021, 12:51:34 PM
No solution for the post combat problem. Vayras' sector has been identified as culprit for most campaign layer lag issues due to fleet spam.
This can be alleviated by using ClearCommands, https://fractalsoftworks.com/forum/index.php?topic=19210, cSmartClear, but it's nothing other than a band aid.
For new saves, do this before starting:

Go to Vayra's Sector\data\config\vayraRaiders
Open warhawk_republic.json
find the line:
"spawnNonEventFleets":true, # OPTIONAL Boolean, default false
    # Causes small, NON-EVENT-RELATED fleets to spawn from ALL markets owned by the faction (i.e. not just bases created by this framework)


and set it to false
do the same for hegemony.json
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Flacman3000 on January 04, 2021, 12:13:04 AM
No solution for the post combat problem. Vayras' sector has been identified as culprit for most campaign layer lag issues due to fleet spam.
This can be alleviated by using ClearCommands, https://fractalsoftworks.com/forum/index.php?topic=19210, cSmartClear, but it's nothing other than a band aid.
For new saves, do this before starting:

Go to Vayra's Sector\data\config\vayraRaiders
Open warhawk_republic.json
find the line:
"spawnNonEventFleets":true, # OPTIONAL Boolean, default false
    # Causes small, NON-EVENT-RELATED fleets to spawn from ALL markets owned by the faction (i.e. not just bases created by this framework)


and set it to false
do the same for hegemony.json

As I expected this does nothing for my after battle lag issue where it slows to a crawl but it seems useful when using a big sector map for the adjusted sector. May I ask what the varya's non event fleets do? does it make more things to kill or just bloats for no reason because I want to know if I'm essentially disabling more spawns of enemies because I like killing things.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: SirHartley on January 04, 2021, 10:15:22 AM
spawns hundreds of small (1-2 ship) fleets that do nothing and never despawn. Single largest contributor to the endemic campaign stutter issues and people running out of RAM to save.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Quantax on January 28, 2021, 06:44:13 AM
I'm having similar performance issues and I can definitely say that battles the triggering event for the slowdown, at least for me. For a while I have observed that FPS seems to tank after sizeable battles, and just a moment ago I was flying around  at pretty stable in-system 60 FPS but immediately after a large(ish) battle my in-system FPS drops to sub-20 and hyperspace FPS is even worse at 12 - 18 FPS (was 40ish before slowdown). FPS don't recover without a game reboot.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: GhostReconZB on March 20, 2021, 02:21:56 AM
I did some observation with this battle triggered slowdown of the game. For the battle to trigger the slowdown, I believe 2 critierias need to be met:
1. The battle should take place in the core sector. 
2. The player needs to be near or in the battle.
For what I found out is that in late game, if u spent all the time exploring the unknow space, u can keep engaging in big battles with remnant fleet or derelict probes without triggering the slowdown. But the same thing can not be said while u are in core sector, even if u just roam around the core sector without engaging in fight as long as u are regularly "exposed" to nearby big fights between AI, at some point the slowdown will still be triggered. My guess is that the reaction script by the "living" faction in the core sector (instead of somewhat dead faction like remnant) will slowly cumlating performance issues until eventually slowdown the game.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: phonon5891 on March 24, 2021, 02:41:22 AM
Just wanted to add my own experiences with this issue. In no particular order:

As mentioned before, so far the only thing that helps is a complete quit and restart of the game.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Flacman3000 on May 14, 2021, 04:49:36 PM
Is this issue still relevant in 0.95a?
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Histidine on May 14, 2021, 05:15:40 PM
Is this issue still relevant in 0.95a?
I'm still getting it on 0.95a (and IIRC it happened on my unmodded/minimally modded run). Haven't tested if the Java 8 workaround still works.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Flacman3000 on May 14, 2021, 05:23:29 PM
Is this issue still relevant in 0.95a?
I'm still getting it on 0.95a (and IIRC it happened on my unmodded/minimally modded run). Haven't tested if the Java 8 workaround still works.

That's unfortunate it seems the memory leak indicator introduced in 0.95a changelog didn't do the trick but still is useful for the future. Going to try Java 8 workaround as well and if it even starts up for me this time ill follow your instructions.

EDIT: Might be dumb but you mentionned simply deleting ..\jre\bin\java.exe in starsector.bat which im using to launch and replace with just java therefore it being java.exe -Djava.library.path=native\windows and so on or just java without the .exe or do I need to specify the directory to the latest java on my computer? I ask this because it opens the cmd for like 1 second and does nothing now. I have allow any java version set to true.

Off topic: I apologize sincerely for asking too many questions on your nex thread I really do respect your work and your efforts its just some information isn't readily available with keyword searches on the forum or some documentation is not readily available. I do not want to come across as annoying by any means.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Histidine on May 15, 2021, 04:26:31 AM
It's just java with no .exe.
If the CMD window disappears without the game starting, add a PAUSE to the end of the .bat file so it keeps the window around and you can see any error message it's printing.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Vind on May 15, 2021, 10:32:58 AM
I got massive slowdown after destroying path battle station and reloading save file after game restart did nothing - switching to oracle 8 java version eliminated slowness after reload but the most puzzling part - next day same "crawling" save file worked fine with game default java. Something with memory fragmentation maybe the issue so immediately reloading game and save file doesnt help due to OS caching.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Gazelem on May 22, 2021, 11:40:45 AM
I've been testing some things and I think I may be having a different issue. I also have been getting the mid and late-game crawl, but it seems to be related to the number of ships I have. Doesn't matter how many OP they have or if they're outfitted or not, but once I go over 10 I drop below 60 fps, and once I go beyond 15 I drop below 45 fps. Here are my computer specs and mod list:

The odd thing is that I spawned large fleets with this mod list and nuked them, probably about a dozen 500 point fleets, and I didn't get any slowness until I started scavenging ships.

Spoiler
Mods:

Lightshow
Trailer Moments
A New Level of Confidence
Adjusted Sector
Better Colonies
Beyond the Sector
Captain's Log
Caymon's Ship Pack
Combat Chatter
Console Commands
DIY Planets
Fluff Ship Pack
Hegemony Expeditionary Auxiliaries
Internal Affairs
Kadur Remnant
LazyLib
Legacy of Arkgneisis
Persean Chroniccles
Quality Captains
Stellar Networks
Supply Foraging
Tahland Shipworks
Vayra's Ship PAck
ZZ Audio Plus
Modified Industry Requirements
Graphicslib (disabled)
[close]

Spoiler
Specs

Windows 10
Processor   Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz, 2592 Mhz, 6 Core(s), 12 Logical Processor(s)
Installed Physical Memory (RAM)   16.0 GB
Total Virtual Memory   29.3 GB
NVIDIA GeForce RTX 2060


I've allocated 4 GB of RAM to Starsector and never come close to that limit. I do seem to have large VRAM spikes, but typically float 1 or 2 GB free
[close]


EDIT:

Found the culprit in my case. It was Legacy of Arkgneisis, which is a shame because I quite like that mod.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Avallac on September 01, 2021, 06:04:35 PM
I keep having some of the same issues as this thread. Even if I use smartclear command from console mod the INTERFACE still stays extremely laggy and it takes minutes to click on something like colony panel or save the game. Super annoying having to save and restart the game every few battles.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: SafariJohn on September 26, 2021, 10:49:13 AM
Think I encountered this slowdown business during my Roider Union playtesting. Kicked on a CPU profiler, but nothing stands out to me. Mods are:

Console Commands
Hostile Intercept
LazyLib
Logistics Notifications
MagicLib
Rebalanced Pilums
Roider Union
GraphicsLib

Screenshots of the most relevant looking stuff from the profile snapshot:
Spoiler
(https://i.imgur.com/P2tGK3I.png)
(https://i.imgur.com/fTaXvf5.png)
(https://i.imgur.com/EGWLk9I.png)
(https://i.imgur.com/augq2nH.png)
(https://i.imgur.com/601EzYJ.png)
(https://i.imgur.com/DmJFQz0.png)
(https://i.imgur.com/NdNmss3.png)
(https://i.imgur.com/WNhefSc.png)
(https://i.imgur.com/ZwhBJKm.png)
(https://i.imgur.com/aH8WQPC.png)
[close]
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on December 10, 2021, 10:28:35 AM
FWIW, I'm doing a heavily modded play through with the usual Nexerlin + Varya's+Lots-o-Faction mods and I'm not having any slowdowns using the JRE8 271 and "aggressive" GC options from Discord:

Code
java.exe -XX:+ShowMessageBoxOnError -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AggressiveOpts -XX:+TieredCompilation -XX:+UseG1GC -XX:InitialHeapSize=2048m -XX:MaxMetaspaceSize=2048m -XX:MaxNewSize=2048m -XX:+ParallelRefProcEnabled -XX:G1NewSizePercent=5 -XX:G1MaxNewSizePercent=10 -XX:G1ReservePercent=5 -XX:InitiatingHeapOccupancyPercent=80 -XX:G1HeapWastePercent=5 -XX:MaxGCPauseMillis=100 -XX:G1HeapRegionSize=2M -XX:+UseStringDeduplication -Xms10512m -Xmx10512m -Xss2m 

In addition to no slowdowns, performance over all is just better.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: temotodochi on December 29, 2021, 01:19:23 PM
with these options starsector wont even start. What's you vmparams like?
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: Nick XR on December 30, 2021, 12:03:21 AM
with these options starsector wont even start. What's you vmparams like?

java.exe -XX:CompilerThreadPriority=1 -XX:+CompilerThreadHintNoPreempt -XX:+DisableExplicitGC -XX:+UnlockExperimentalVMOptions -XX:+AggressiveOpts -XX:+TieredCompilation -XX:+UseG1GC -XX:InitialHeapSize=2048m -XX:MaxMetaspaceSize=2048m -XX:MaxNewSize=2048m -XX:+ParallelRefProcEnabled -XX:G1NewSizePercent=5 -XX:G1MaxNewSizePercent=10 -XX:G1ReservePercent=5 -XX:InitiatingHeapOccupancyPercent=80 -XX:G1HeapWastePercent=5 -XX:MaxGCPauseMillis=100 -XX:G1HeapRegionSize=2M -XX:+UseStringDeduplication -Djava.library.path=native\windows -Xms8096m -Xmx8096m -Xss2m -classpath janino.jar;commons-compiler.jar;commons-compiler-jdk.jar;starfarer.api.jar;starfarer_obf.jar;jogg-0.0.7.jar;jorbis-0.0.15.jar;json.jar;lwjgl.jar;jinput.jar;log4j-1.2.9.jar;lwjgl_util.jar;fs.sound_obf.jar;fs.common_obf.jar;xstream-1.4.10.jar -Dcom.fs.starfarer.settings.paths.saves=..\\saves -Dcom.fs.starfarer.settings.paths.screenshots=..\\screenshots -Dcom.fs.starfarer.settings.paths.mods=..\\mods -Dcom.fs.starfarer.settings.paths.logs=. com.fs.starfarer.StarfarerLauncher


This is using JRE8 271 and you'll have to force windows to use application scaling (search for it if you're not sure how).  You'll also need probably 12GB of system memory at least.
Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: temotodochi on December 30, 2021, 05:45:31 PM
Thanks for the details, however starsector wont start with that in vmparams, not even the launcher. There are several issues. You didn't use code (#) formatting, so forum broke your paste by trying to cut it in places to fit he page width.

Also 8096 might work, but is not correct. Java likes powers of ^2. Double of 4096 is 8192. Might be simpler just to state =8G.

I think 16 gigs of ram is bare minimum these days, i personally have run on 32gigs for years already.

Title: Re: [Late Game] Battles & Colony Management ruin FPS gradually & permanently.
Post by: corporeal on December 03, 2022, 01:24:30 AM
Didn't find a more recent thread. I'm still having this issue but found a new technique for anyone having trouble on a linux system that uses systemd.

As per previous posts, this is now my starsctor.sh:
Code
./jre_linux/bin/java -server -XX:+UseLargePages -XX:+UseParallelGC -XX:-UseGCOverheadLimit -XX:CompilerThreadPriority=1 -XX:+CompilerThreadHintNoPreempt -Djava.library.path=./native/linux -Xmn1g -Xms4g -Xmx4g -Xss4m -classpath janino.jar:commons-compiler.jar:commons-compiler-jdk.jar:starfarer.api.jar:starfarer_obf.jar:jogg-0.0.7.jar:jorbis-0.0.15.jar:json.jar:lwjgl.jar:jinput.jar:log4j-1.2.9.jar:lwjgl_util.jar:fs.sound_obf.jar:fs.common_obf.jar:xstream-1.4.10.jar -Dcom.fs.starfarer.settings.paths.saves=./saves -Dcom.fs.starfarer.settings.paths.screenshots=./screenshots -Dcom.fs.starfarer.settings.paths.mods=./mods -Dcom.fs.starfarer.settings.paths.logs=. -Dcom.fs.starfarer.settings.linux=true com.fs.starfarer.StarfarerLauncher
#./jre_linux/bin/java -server -XX:-UseGCOverheadLimit -XX:+UseParallelGC -XX:CompilerThreadPriority=1 -XX:+CompilerThreadHintNoPreempt -Djava.library.path=./native/linux -Xms4g -Xmx4g -Xss4m -Xmn64m -classpath janino.jar:commons-compiler.jar:commons-compiler-jdk.jar:starfarer.api.jar:starfarer_obf.jar:jogg-0.0.7.jar:jorbis-0.0.15.jar:json.jar:lwjgl.jar:jinput.jar:log4j-1.2.9.jar:lwjgl_util.jar:fs.sound_obf.jar:fs.common_obf.jar:xstream-1.4.10.jar -Dcom.fs.starfarer.settings.paths.saves=./saves -Dcom.fs.starfarer.settings.paths.screenshots=./screenshots -Dcom.fs.starfarer.settings.paths.mods=./mods -Dcom.fs.starfarer.settings.paths.logs=. -Dcom.fs.starfarer.settings.linux=true com.fs.starfarer.StarfarerLauncher

The difference is that UseLargePages is enabled.

Additionally this wrapper script is now used to call starsector.sh:
Code
systemd-run --scope -p MemoryMax=7G -p MemorySwapMax=32M --user ./starsector.sh &>/dev/null &
while [ TRUE ]; do
echo 'Waiting 1 minute...'
sleep 55s
echo 'Clearing cache...'
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
sleep 5s
free -h
done

systemd-run --scope -p MemoryMax=7G -p MemorySwapMax=32M --user ./starsector.sh &>/dev/null &
--This forks starsector into a process that is restricted to 7G of my available 8G of ram (including cache!). This allows my computer to run other programs smoothly.
--Greatly reduces the burning of my SSD drive by restricting swap.

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
This is a REALLY aggressive method of clearing memory. See https://linux-mm.org/Drop_Caches and google for more info.

lspci -k:
Code
00:00.0 Host bridge: Intel Corporation Broadwell-U Host Bridge -OPI (rev 09)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: bdw_uncore
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 5500 (rev 09)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: i915
Kernel modules: i915
00:03.0 Audio device: Intel Corporation Broadwell-U Audio Controller (rev 09)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: snd_hda_intel
Kernel modules: snd_hda_intel
00:04.0 Signal processing controller: Intel Corporation Broadwell-U Processor Thermal Subsystem (rev 09)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel modules: processor_thermal_device_pci_legacy
00:14.0 USB controller: Intel Corporation Wildcat Point-LP USB xHCI Controller (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: xhci_hcd
Kernel modules: xhci_pci
00:16.0 Communication controller: Intel Corporation Wildcat Point-LP MEI Controller #1 (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: mei_me
Kernel modules: mei_me
00:1b.0 Audio device: Intel Corporation Wildcat Point-LP High Definition Audio Controller (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: snd_hda_intel
Kernel modules: snd_hda_intel
00:1c.0 PCI bridge: Intel Corporation Wildcat Point-LP PCI Express Root Port #1 (rev e3)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: pcieport
00:1c.2 PCI bridge: Intel Corporation Wildcat Point-LP PCI Express Root Port #3 (rev e3)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: pcieport
00:1d.0 USB controller: Intel Corporation Wildcat Point-LP USB EHCI Controller (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: ehci-pci
00:1f.0 ISA bridge: Intel Corporation Wildcat Point-LP LPC Controller (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: lpc_ich
Kernel modules: lpc_ich
00:1f.2 SATA controller: Intel Corporation Wildcat Point-LP SATA Controller [AHCI Mode] (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: ahci
00:1f.3 SMBus: Intel Corporation Wildcat Point-LP SMBus Controller (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: i801_smbus
Kernel modules: i2c_i801
00:1f.6 Signal processing controller: Intel Corporation Wildcat Point-LP Thermal Management Controller (rev 03)
Subsystem: Matsushita Electric Industrial Co., Ltd. Device 8338
Kernel driver in use: intel_pch_thermal
Kernel modules: intel_pch_thermal
02:00.0 Network controller: Intel Corporation Wireless 7265 (rev 59)
Subsystem: Intel Corporation Dual Band Wireless-AC 7265
Kernel driver in use: iwlwifi
Kernel modules: iwlwifi


Output of free -h with starsector off:
Code
               total        used        free      shared  buff/cache   available
Mem:           7.7Gi       1.1Gi       5.9Gi       232Mi       618Mi       6.0Gi
Swap:             0B          0B          0B


lsmem:

RANGE                                  SIZE  STATE REMOVABLE BLOCK
0x0000000000000000-0x00000000dfffffff  3.5G online       yes  0-27
0x0000000100000000-0x000000021fffffff  4.5G online       yes 32-67

Memory block size:       128M
Total online memory:       8G
Total offline memory:      0B


Before I started clearing the cache it would stay over 1.5G even after starsector closed. Worse, after several successive restarts memory would overload and start dumping to my SSD!. Basically I got randomly bricked and had to hard-reboot.

Still need restart now and then but no more bricking and restarts are less frequent. 0.95.1a-RC6



mod list:
Code

{"enabledMods": [
  "lw_lazylib",
  "MagicLib",
  "shaderLib",
  "dronelib",
  "$$$_lightshow",
  "su_Concord",
  "lw_console",
  "pantera_ANewLevel40R",
  "aaacrew_replacer",
  "Adjusted Sector",
  "anotherportraitpack",
  "portrAIt",
  "raccoonarms",
  "AttunedDriveField",
  "automatedcommands",
  "lw_autosave",
  "beyondthesector",
  "CaptainsLog",
  "istl_dassaultmikoyan",
  "edshipyard",
  "fleetsizebydp",
  "sun_flux_reticle",
  "GrandColonies",
  "HexShields",
  "hte",
  "hiigaran_descendants",
  "immersionFriendlyPortraitPack",
  "IndEvo",
  "interestingportraitspack",
  "Interstellar Federation Refurbished",
  "lights_out",
  "missingships",
  "su_CarrierHullmod",
  "sun_new_beginnings",
  "nexerelin",
  "scan_those_gates",
  "console_overlord_additionalcommands",
  "clearCommands",
  "mkportraits",
  "personal_portratis",
  "pt_qolpack",
  "HMI",
  "Neutrino",
  "forge_production",
  "more_hullmods",
  "wyv_planetaryShieldAccessControl",
  "scf",
  "planet_search",
  "QualityCaptains",
  "ArkLeg",
  "swp",
  "speedUp",
  "stelnet",
  "Terraforming & Station Construction",
  "diyplanets",
  "transpoffder",
  "US",
  "whichmod",
  "audio_plus",
  "tahlan",
  "officerExtension",
  "harmless-slipstreams",
  "wisp_NeutrinoDetectorMkII",
  "progressiveSMods",
  "timid_admins",
  "mayu_specialupgrades",
  "armaa",
  "exshippack",
  "exshippack_armaacompat",
  "mySettings"
]}