immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
214 stars 41 forks source link

Stimulus performance issue on AWS using WebGL: Jittery and slow by seconds #125

Closed AbhayKoushik closed 2 years ago

AbhayKoushik commented 2 years ago

Hello! I am developing an experiment where the subjects choose between the GameObjects that are moving in a specific rotary fashion. The performance drastically decreases: The objects which move in a smooth circular fashion with one full rotation per second on local computer with FileSaver mode now only have 2 or 3 position updates per second while running online using AWS.

Below are some additional points that I'd like to share and would love to have your opinion on!

1) Given my experiment takes in the choice of the GameObjects on screen as input from the subjects, I checked with both the keyboard and mouse clicks as inputs from the users to choose a position on the screen (indicative of the corresponding objects of choice), there is not much of a difference, both are laggy and the lag between the actual input and their feedback is quite a lot (almost a second or so). 2) There are about a hundred GameObjects loaded on the scene but only 3 objects are enabled by their MeshRenderers at a time per trial. 3) I read that WebGL is poor with multi-threading but there are only 2 StartCoroutine() functions in my program, one co-routine (for ending the task) inside the other coroutine(for starting the task trial) with no explicit multi-threading, could those be harming the performance? 4) The GameObjects are set to motion using the transform.rotateAround() function in the Update() function outside the coroutines, is that a problem? 5) Even when the GameObjects are static and not animated to move in the Update() function, there seems to be a lag between the user input and the feedback before going to the next trial.

Please let me know if you need any further information from my side. I'd love to have your insights on how I could make my experiment smoother, looking forward!

Cheers, Abhay

jackbrookes commented 2 years ago

Hi, I would recommend you create a test scene to narrow down the cause of your issues. Does a simple scene without UXF run well? Do the UXF examples run well? I run much more complex experiments than what you are describing with no problem.

You can also use the Unity Profiler to debug performance. Even checking out which scripts are taking a long time to execute whilst in the editor can be useful.

AbhayKoushik commented 2 years ago

Thanks for a quick response, Jack!

I figured that rendering has the highest cost in my profiler. I optimized physics, shadows and ray casters to an extent. According to my build report, the maximum size is of the meshes (32.1 mb), included DLLs (13.4 mb) and then the textures (5.4 mb). Any particular ways to optimize that?

(Not so) Surprisingly, my experiment builds and works well with WebGL on some computers (eg: default resolution - 1920 x 1080) but gets very jittery in some others (eg: default resolution - 3840 x 2160).

Would love to have your thoughts on this! I'd appreciate any suggestions to make it run smoother

jackbrookes commented 2 years ago

This is probably outside UXF, so all I can do is point you in the right direction:

Performance in WebGL https://docs.unity3d.com/Manual/webgl-performance.html

As it suggests, you should use the Unity Profiler to check out what is taking so long to render.

You should look more at number of polygons on screen, and number of batches, rather than the file size of the assets.

If it is purely a resolution issue, there are some assets to help downscale the resolution. https://assetstore.unity.com/packages/tools/utilities/webgl-fps-accelerator-174567 However, I would say for a WebGL task, do you really need to display it on a 4K screen?