NPBruce / valkyrie

Valkyrie GM for Fantasy Flight Board Games
Apache License 2.0
506 stars 105 forks source link

Slow response #836

Closed scrubbless closed 6 years ago

scrubbless commented 6 years ago

Description of Problem or Question

Hi, I am writing a scenario and it has got rather large, approximately 40mb in size.

Mostly this is sound and image files which I have compressed as much as possible (pngoptimizer and cropping sounds).

When using the editor on my gaming pc, quad core i7 skylake, 32gb ram, SSD. It can still take ~5 seconds to load the components menu and every click, selecting an event can take longer. It really adds up to a lot of wasted time. On my slower laptop (x1 Carbon, quad core i7, 8gb ram, SSD) it can get even slower.

I have loaded Valkyrie setting the quality to fastest and assigned high cpu priority to Valkyrie. Full screen is slightly better but it's still painfully slow at times.

Is there anything I can do to speed things up?

Valkyrie Version

2.01

Attach Save, Quest or Scenario

I won't attach anything yet as I have nearly finished the scenario and it may be easier to review when complete.

NPBruce commented 6 years ago

The file size shouldn't make a difference here. Only when selecting images should it matter, and then only the first time (after that it should be fast).

Can you attach the scenario here (remove the images and audio if you need to)? Also, is it slow immediately or only after you have gone to the image selection screen? This will load all the images and it is possible that a memory limit is being hit (Unity is running as 32 bit so there is a 4GB limit).

It could be that the issue has nothing to do with scenario file size and is an issue with the component data.

scrubbless commented 6 years ago

Can you pick up the file from my GitHub? https://github.com/scrubbless/ScenariosInProgress

If I remove the images will it cause issues to troubleshoot?

If not then I'll upload it tomorrow (need a pc to remove the images).

NPBruce commented 6 years ago

I can pull it from github, I will have a look when I can. You can check Valkyrie's memory usage to see if this is the problem. Note that it has to run on mobile devices anyway, so just increasing this limit is probably not a good solution (unless it is only required for the editor perhaps).

scrubbless commented 6 years ago

It can be a little sluggish to end rounds towards the later rounds. But runs ok on my phone.

AlI though it crashes when using the old journal item at the moment. I've been working on that.

How can I go about checking it's memory usage?

scrubbless commented 6 years ago

Ok so when I bring up the editor it spikes to 700mb memory usage: image

I did a save and tabbed out to work on other things not Valkyrie for a while, in that time it settled down to nearer 150-200mb.

I opened up a UI element, clicked to select an image and it went up to around ~300mb.

Once an image was selected I dropped back to an event and it settled to ~200b again.

I then his "Save & Test" and it spiked up to over 700mb again, the application went into "Not responding" in this time (some times windows will ask me if I want to close it, but it usually catches up". image

(the screenshot shows 300mb, but it climbed to 700 before the scenario started).

Once it has loaded the memory dropped back down to ~200mb. image

NPBruce commented 6 years ago

I've had a quick look. I get the same memory usage, which is fine.

The interesting part is that performance for me is fine when it is on the starting 'Quest' component, but goes bad when a different component is selected. When it goes bad it is not just the component selection, the entire UI including scrolling, paning and zoming go bad. Also the CPU load is high when the window is in focus, but not when it isn't.

Does this match your observations?

It suggests that there is something it is doing when it renders each frame that is way too slow. This is interesting, because Valkyrie does almost nothing based on frame rendering, almost everything is based on an event (ie: clicked a button). This suggests a problem with Unity which may be annoying to track down. Valkyrie must have some control over it however, as performance it good at first.

My time allowance is still poor at the moment unfortunately.

scrubbless commented 6 years ago

Just been using it with the Task Manager up and have noticed that when I click components, the memory spikes over 700mb and there is a delay. So I think it probably is memory usage: image

scrubbless commented 6 years ago

I've had a quick look. I get the same memory usage, which is fine.

The interesting part is that performance for me is fine when it is on the starting 'Quest' component, but goes bad when a different component is selected. When it goes bad it is not just the component selection, the entire UI including scrolling, paning and zoming go bad. Also the CPU load is high when the window is in focus, but not when it isn't.

Does this match your observations?

Yeh thats it. Once you hit the components menu it gets grumpy. I periodically save and close Valkyrie and go back in which helps. I suspect it is just because I have loads and load of components.

If I open up a new scenario from scratch its really responsive.

My time allowance is still poor at the moment unfortunately.

No worries @NPBruce, thanks for jumping on this to have a look. I will work around it (close out and go back in from time to time), as I said - this Scenario is nearly done.

redwolf2 commented 6 years ago

When I clicked on "Components" it took 5 seconds to open. I found out, this is due to the amount of items, that are displayed, which is 2594. For each item, there is a UIElement, that will be created. I guess it is just too much for Unitys ui system. Maybe the fix is something like an infinite list (https://www.youtube.com/watch?v=uVTV7Udx78k).

The slowdown will happen between those two break points: items

NPBruce commented 6 years ago

I am not convinced that is the problem. Even once the components list is closed unity runs terribly, including from frame to frame. The constantly running code on the Valkryie side is click/drag code (used everywhere and very light) and the spite pulser (only used for some component selections, and the problem exists when this isn't used).

This list shouldn't be too hard for unity, but perhaps it is triggering something else to go wrong. Note that I found that the first time the component list is loaded it worked fine, so this suggest it is something in loading a component (as apposed to the list) which is causing the problem.

Unfortunately the profiler in Unity sucks.

redwolf2 commented 6 years ago

cameracontroller

I commented out the content of CameraController.FixedUpdate() for testing purposes. No more slowdowns.

redwolf2 commented 6 years ago

I think I found it. Seems to be the ray casting inside FixedUpdate(). I moved it to the Update() method. https://github.com/NPBruce/valkyrie/pull/838 However:

Don’t use use Raycasts inside a FixedUpdate() function, sometimes even inside an Update() may be an overkill. https://unity3d.com/de/learn/tutorials/topics/physics/physics-best-practices

Maybe we could use some other method instead of raycasting (or optimize it so that it isn't casted on every update) to find out if the cursor is intersecting a board component!?

This issue might also be related to https://github.com/NPBruce/valkyrie/issues/704

NPBruce commented 6 years ago

Great work!

NPBruce commented 6 years ago

Merged for inclusion in 2.1

scrubbless commented 6 years ago

Well done guys, look forward to testing in 2.1!

scrubbless commented 6 years ago

Is there any easy hotfix I can do until 2.1 is released.

I am struggling to do anything on my scenario, as it takes up to 5 seconds every button press for Valkyrie to catch up, is making it almost impossible to work on any other machine than my gaming rig (which is still slow going).

On a side note, I have noticed that if I zoom right in to the board it responds a little quicker. Especially if the camera location animation is running.

BenRQ commented 6 years ago

Beta test version is now available with merge of the fix for this issue: https://github.com/BenRQ/valkyrie/releases/tag/release%2F2.1%2FBrynhildr_2.1.0b