UnityWebRequest very slow

We found that when we built a project with Unity 2020.3.22 and noticed that the duration of sending a webRequest and receiving the response is really long!

We also tried to build the project with Unity 2021.2.4 (the latest version) but the duration is still long. So we tried to build it with Unity 2020.3.7 and found that the duration is short!

In this case, we call the same address “https://www.google.com/” and we are in the same predicament when we call the game server.

Here’s the details for your reference.

    /// <summary>
    /// connect url
    /// </summary>
    string _url = "https://www.google.com/";

    /// <summary>
    /// Send UnityWebRequest
    /// </summary>
    public void SendGetRequest()
        if (_Coroutine == null)
            _startTime = Time.realtimeSinceStartup;
            _Coroutine = StartCoroutine(SendGet());

    IEnumerator SendGet()
        UnityWebRequest webRequest = UnityWebRequest.Get(_url);
        //webRequest.timeout = _timeOut;
        webRequest.useHttpContinue = false;
        yield return webRequest.SendWebRequest();

        if (webRequest.result == UnityWebRequest.Result.ProtocolError ||
            webRequest.result == UnityWebRequest.Result.ConnectionError)
            _OnLogEvent.Invoke(string.Format("[Log] UnityWebRequest error 

-url = {0}
-result = {1}“, _url, webRequest.error));
float spendTime = Time.realtimeSinceStartup - _startTime;
_OnLogEvent.Invoke(string.Format(”[Log] UnityWebRequest success
-url = {0}
-spendTime = {1}", _url, spendTime));
_Coroutine = null;

        yield return null;

You seem to have a strange view what is long and what is short. When I load google in Firefox and check the network tab (and the time sub tab) how long the response just for the main page took, it’s about 143ms on my machine. The difference between your tests is under twice the time. There could be countless reasons for that. It’s possible that Unity changed the security layer. When testing inside my browser google uses elliptic curve cryptography while in the past (and still used today) RSA was more common. HTTPS is “relatively” slow by definition since it always includes a TLS connection which is the main part which makes the request slow. Also since you use a coroutine ,which is absolutely correct, the response can only be processed at the next frame after the response arrived. So you get an additional 0 up to detlaTime seconds delay per request. So on average half the frame time.

Furthermore your current test is violating google’s terms of services because the website is meant for human interaction and extensive bot usage is not allowed. So google “may” even detect the user agent of the Unity player and artificially delay the response to trottle traffic. You said you have a similar issue when connecting to your own server? As I said, webrequests are inherently slow, especially when doing seperate requests. While for certain game types using HTTP / HTTPS is fine, it’s certainly not suitable for most realtime environments. So I’m not sure what you’re asking here. Technologies changes and you will always see differences between Unity versions. Though the response times are completely in the reasonable range for HTTPS, so I’m not sure what you expect.