Hubs-Foundation / hubs

Duck-themed multi-user virtual spaces in WebVR. Built with A-Frame.
Mozilla Public License 2.0
2.12k stars 1.42k forks source link

[MacOS][Safari] Performance issues occur and a high CPU usage while navigating the room #4423

Open Softvision-RemusDranca opened 2 years ago

Softvision-RemusDranca commented 2 years ago

[Affected Versions]:

[Affected Platforms]:

[Prerequisites]:

[Steps to reproduce]:

  1. Spawn some objects inside inside the room.
  2. Move around the room and interact with the objects (for approx. 5 minutes).
  3. Observe the behavior.

[Expected results]:

[Actual results]:

[Notes]:

┆Issue is synchronized with this Jira Task

takahirox commented 2 years ago

I can reproduce the very high CPU usage on my Mac.

Multi posts with https://github.com/mozilla/hubs/issues/4411#issuecomment-882788300, I confirmed that CPU usage on Mac is very high even on a simple Three.js positional audio example so I speculate the performance problem may be very relevant to the spacial audio issue. If it's the root issue, perhaps disabling the spacial audio on MacOS/iOS may be a workaround so far as @brianpeiris suggested.

And this issue report reminds me of that Fernando often complained that his fan is busy when he opens Hubs on his Mac.

takahirox commented 2 years ago

We disabled Positional (Panner) audio for Safari. We speculated Positional Audio bug on Safari may be the major reason of the high CPU. After applying this change, the CPU usage on my MacOS Safari is around 100%. It's still a bit higher than Chrome and Firefox, but it's much better than before like 140%.

Would you test if you can still reproduce the problem? @Softvision-RemusDranca For me, I think CPU usage 100% may be acceptable so far.

takahirox commented 2 years ago

@Softvision-RemusDranca Can you test again on the latest MacOS to check if it's still reproducible?

Softvision-RemusDranca commented 2 years ago

@takahirox I do see improvements, on a normal usage I also have around 90% to 100% CPU (no objects and alone in the room). However, it goes up after importing objects and entering the room with new users.

takahirox commented 2 years ago

@Softvision-RemusDranca

it goes up after importing objects and entering the room with new users.

Does the CPU usage keep high after importing objects or someone enters a room on your Mac?

On my MacOS the CPU usage spikes to over 100% like to 110% at the moment when an object is imported but it goes down to natural like 80-90% soon after that. I think it would be acceptable (although I'm really not sure what over 100% CPU usage means).

Softvision-RemusDranca commented 2 years ago

@takahirox

Does the CPU usage keep high after importing objects or someone enters a room on your Mac?

For me it stays around 120%, it definitely is an improvement, but I do see small performance issues while navigating the room when having multiple objects in the room. The spikes are higher right when uploading objects, but it goes down like you said.

takahirox commented 2 years ago

@Softvision-RemusDranca

Thanks. Can you share your MacOS spec, like CPU, memory, GPU, and s on?

Softvision-RemusDranca commented 2 years ago

@takahirox I've tried to mimic a real time use of Hubs, having 3 users inside the room and imported two videos as well. Given this scenario I had everything open for around 40 minutes, and I did have a high CPU usage at the end. In the first minutes the CPU usage staid around 100%, but it kept on rising while continuing no navigate, communicate and so on, until it get to around 140% - 150%. Here ia a screed recording that captures the stats at the end of testing: link.

Specs: MacBook Pro (Retina, 13-inch, Late 2013), Processor: 2,8 GHz Dual-Core Intel Core i7; Memory: 16 GB 1600 MHz DDR3

takahirox commented 2 years ago

@Softvision-RemusDranca

Thanks for sharing the spec.

Specs: MacBook Pro (Retina, 13-inch, Late 2013),

I guess the reason why CPU usage is so high on your mac is the mac is old? Mine is 2017.

I'm thinking of optimizing Hubs for low-end models in 2022, but let me lower the priority so far because it looks at least better than before.

brianpeiris commented 2 years ago

I suspect the extreme CPU usage here was due to Safari's positional audio bug, as reported in https://bugs.webkit.org/show_bug.cgi?id=227199

If we still have access to older MacBook models, we should try to reproduce the CPU usage issue with Safari 15.4, since it seems they might have fixed the underlying bug.