Photon Voice slow

Running into a voice issue that's killing our performance across the board, but particularly unusable on Quest. Specifically our performance tanks as soon as "PhotonVoiceNetwork singleton" appears in the scene (DontDestroyOnLoad), even when we switch back to offline mode and no voice avatar is in the scene.

Running a deep profile, it looks like it's coming from some sort of encryption, even when encrypt is turned off. Attaching an image for more info. Note that this is in offline mode. The inspector is showing our avatar prefab which isn't even in the scene itself. However, stats are identical when avatars are loaded and active in a voice room.

Unity 2019.2.1f1
Voice 2.17
PUN 2.18



  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @lmartell,

    This is not Voice specific or related to the "Encrypt" toggle which encrypts the transmitted stream.

    What you are seeing is the encryption exchange phase, where keys are being exchanged between client and server.
    It should also be the case for the PUN client.
    This should happen when connecting to the server initially and authenticating.
  • lmartell
    edited July 2020
    Ah, good to know what it is. I did another test and it's not just happening on connect, it's happening several times a second as long as the game is running, even when in offline mode. In this profiler, each of those peaks I marked is the same function spiking.

    EDIT: One more detail... for sanity I turned off the voice functionality, but kept all the multiplayer stuff. With no voice it runs great with no spikes.

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @lmartell,

    In an upcoming update we will make Voice integration with PUN work better when PUN is in offline mode: voice client will not try to follow PUN client (connect / join room).
  • lmartell
    edited July 2020
    Ah that's great. Well for now I'm happy to find a workaround, but might still need a little help figuring out how to do that as it's happening everywhere, not only in offline mode.

    So after a few more tests, the problem seems to occur after connecting and loading a new scene.
    • Main Menu - as soon as we connect to a room, voice avatars are loaded. There are no performance problems in this scene and voice works great.
    • Load Level - from this point on we get spikes whether we're in multiplayer or single player. Note that voice still works, it's just this performance problem. No errors in the console.
    • Returning to Main Menu - So here's where I'm really confused... when we return to the main menu (still in the photon room), everything is just fine. Voice works, no spikes. It's a freshly loaded version of that scene, so it's not like anything was persisting.

    It's definitely something with voice, as when I disable voice (I just comment out the line where I instantiate the voice prefabs) there's no problems.

    Also a note that I've tried keeping the voice prefabs persistent (DontDestroyOnLoad) as well as instantiating them fresh in each scene.

    If I only create the voice within a level (no voice in main menu), everything works fine while I'm in that scene. But if I launch a different scene, the spikes start. So again, it seems that once voice has been created for the first time, performance issues are a problem as soon as you go to a different scene.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @lmartell,

    What Photon Voice version is this?
    Can you reproduce with any of the demo scenes?

    Can you increase log level for PhotonVoiceNetwork.Instance.LogLevel to INFO or ALL?
    Or enable SupportLogger?
    We are trying to find out if the voice client is constantly disconnecting and reconnecting again (voice client state changes) as the key exchange should happen once during the initial connection to the 'first server'.
    You could also try disabling AutoConnectAndJoin or AutoLeaveAndDisconnect and see if the spikes are there.

    The idea is to try to reproduce this.
    So maybe if you have minimal repro steps or minimal repro project.
  • Solved it!!!

    So it was absolutely user error. Turns out in my level (not main menu) prefab setup, I already had a PhotonVoiceNetwork from a previous implementation, but now that one was getting created automatically in the main menu there were two PhotonVoiceNetworks in the scene. There was a log entry "An instance of PhotonVoiceNetwork is already set." but it was only a warning so it didn't show up until I increased the log level like you suggested. Might be worth elevating that to an error since it causes problems, but was absolutely a PEBKAC error. Thanks for your help diagnosing!
  • Thanks for the update! Glad you found this!
    Yes, I guess that should be an error or somehow prevented. Took a note.