SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
84 stars 18 forks source link

Threading / Staggering Structure/Barricade load #936

Closed ghost closed 1 year ago

ghost commented 5 years ago

It would be nice if loading Barricade or Structure Regions was Threaded/non-blocking (perhaps using the Unity Job System), I understand if this is too much or something you just don't want to do for 3.0, but it would be really nice. The lag caused by players rendering in a large amount of barricades especially has been a growing pain, back in the day it could completely crash people, as far as I know nowadays it cannot, but it certainly making flying a jet over a large town extremely difficult with freezing for 4-5 seconds, coming back, freezing again.

To replicate this, just set up a server, get a good amount of barricades/structures in a region and then unrender/unload them and move back to load in the region again, and you will experience the freeze.

SDGNelson commented 5 years ago

It is frustrating, there was some work on it a few months ago, but now the biggest performance cost is from instantiating all the buildable prefabs. Staggering the instantiation over multiple frames would help, but has the problem of dealing with network updates received while the object does not exist yet. I think there are a few refactoring steps that will need to be done, and should be done eventually, but no ETA yet:

  1. Rewrite "SteamChannel" class and related functions
  2. Type-safe RPCs
  3. Clean up networked object addressing
  4. Queue RPCs for not-yet-instantiated objects
  5. Fix the actual instantiation issue 😋
SingleThreadedWorld commented 3 years ago

I've been seeing that there has been a lot of progress made with Networking and Unity Version, is this next on the list or something you plan on fixing soon? I figured I would post here because a lot of times people assume you know about bugs and issues, when in relatively no one has bothered to report them. This is still a pretty annoying issue that is very prevalent, people love to blame the server as well for it. You can even see it on many youtuber's videos where they have to cut around the lag lines.

I understand that loading regions in chunks or non-blocking is a big ask, instead, maybe you could allow us to configure the amount of regions and add regions on the height axis as well? Right now for example if someone has a huge skybase in the middle of PEI at max height, you will still get crazy loading spikes all around it. As well as allowing us to increase the amount of regions should in theory help reduce those larger lag spikes into smaller ones, as well as helping a bit with regions coming out of sync. (As far as I can tell, super large size maps have the same amount of regions as tiny maps, which results in a lot of RP servers running those big maps and having lots of big loading spikes)

At least I hope this is not an issue in unturned ii

SDGNelson commented 3 years ago

Not exactly next on the list because it depends on the other elements of the netcode rewrite, and even then the barricades will need a rewrite to use the enhancements, but it is a priority. There are also a bunch of misc requests from map creators that need doing.

The region density is very hardcoded and unlikely to be changed. They have a fixed size regardless of map size however.

It is not an issue in Unturned II.

SDGNelson commented 3 years ago

Noting that I am planning for this wider issue to be my primary goal in 2021. From the netcode changes to structure pooling.

ghost commented 3 years ago

Noting that I am planning for this wider issue to be my primary goal in 2021. From the netcode changes to structure pooling.

That's exciting news, I'm assuming it will be a lot further in 2021 than right now, but I'd be more than happy to test out these changes extensively, hopefully avoiding the same situation that happened with the UI changes.

On a related note, I'm unsure how realistic it is, but it would be nice if possible there was an in-game option for clients to load in all barricade/structure regions (or maybe just not unload them) to try to avoid these lag spikes. As far as I can see it would work fine with the existing code, and servers already do this, just without rendering them. There of course would be a performance trade-off, but it could be something for people with decent PC's to try. Figured I would at least suggest it, as it seems that it could be a somewhat decent quick patch to try to ease issues with this.

SDGNelson commented 3 years ago

Thanks Miku! In case you are interested here is a blog post outlining the changes planned: https://blog.smartlydressedgames.com/unturned-in-2021/

Theoretically yes the entire map could be constantly synced as a temporary workaround, but I think especially on dense servers the overhead would be insane. I intend to start work on these changes sooner than later, so for prioritizing temporary workarounds I would probably do the per-server asset table you and baranmod were discussing instead.