NavidK0 / SimpleGraphQL-For-Unity

A simple graphQL client that allows one to use .graphql files (or code) for queries, mutations, and subscriptions with Unity.
MIT License
34 stars 18 forks source link

Slower Calls After Update #31

Closed RPloutarchou closed 2 years ago

RPloutarchou commented 3 years ago

Hi, I have been using SimpleGraphQL package for one of the games I am developing and recently when I update to the latest version I noticed a bit of a lag when making requests. Not sure where the problem is but the lag is noticeable. The package version I was using before is 1.1.3 and I have updated to version 1.2.0.

NavidK0 commented 3 years ago

Hi, I have been using SimpleGraphQL package for one of the games I am developing and recently when I update to the latest version I noticed a bit of a lag when making requests. Not sure where the problem is but the lag is noticeable. The package version I was using before is 1.1.3 and I have updated to version 1.2.0.

Is it possible for you to provide a test project or some test code? This type of problem is really hard to debug without additional information because it could really be anything causing it.

RPloutarchou commented 3 years ago
        Thanks for the reply, I will provide you with some test code first thing on monday.Rafael PloutarchouSoftware Developer Phone: +357 22255604Mobile: +357 99955085Email: ***@***.*** www.spectrum.games   ---- On Fri, 20 Aug 2021 22:23:04 +0300  Navid ***@***.***> wrote ---- 

Hi, I have been using SimpleGraphQL package for one of the games I am developing and recently when I update to the latest version I noticed a bit of a lag when making requests. Not sure where the problem is but the lag is noticeable. The package version I was using before is 1.1.3 and I have updated to version 1.2.0.

Is it possible for you to provide a test project or some test code? This type of problem is really hard to debug without additional information because it could really be anything causing it.

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.

RPloutarchou commented 3 years ago

Hi again I have attached two files one showing the older version and one showing the newer version. I use this code to get data from the server with the SimpleGraphQL package and then deserialize the data with Newtosoft.JSON and add them to an instantiated object on me scene usually on a scroll view. The delay occurs when unity is processing/is waiting on the query and while on the older version the object instantiation was almost instant on the newer version their is a noticeable lag on this part. I am not sure whether this is a problem with this particular package or with the newer version of unity but I would appreciate it If you take a look at it. The scripts I have attached are abstract versions of the scripts I am using In most of my app. Thanks again for the reply. OldVersion.txt NewVersion.txt

NavidK0 commented 3 years ago

Hi again I have attached two files one showing the older version and one showing the newer version. I use this code to get data from the server with the SimpleGraphQL package and then deserialize the data with Newtosoft.JSON and add them to an instantiated object on me scene usually on a scroll view. The delay occurs when unity is processing/is waiting on the query and while on the older version the object instantiation was almost instant on the newer version their is a noticeable lag on this part. I am not sure whether this is a problem with this particular package or with the newer version of unity but I would appreciate it If you take a look at it. The scripts I have attached are abstract versions of the scripts I am using In most of my app. Thanks again for the reply. OldVersion.txt NewVersion.txt

So I reduced your test cases to just testing the queries with a stopwatch and I was unable to find any significant difference between the package versions. The only difference is the ".ToRequest()" extension method in query.ToRequest(). I've attached my files in case you want to try them out:

SimpleGraphQLTest.zip

If you do try it out and find significant differences in the actual query calling, it may be a platform issue or another deeply ingrained problem.

Please note that the first connection will always be slower than the others because of the WebSocket initialization handshake process. Subsequent calls will reuse the same WebSocket so they are much faster. (All GraphQLClient instances use the same WebSocket too.)

As for your issue, I believe that you are noticing lag possibly because of NewtonsoftJSON's deserialization. It's just an educated guess, but you can try using JSONUtility instead and seeing if that helps. I believe your data structure is simple enough to work. Do let me know how it works out. It may just be a problem with either the deserialization or the gameObject instantiation itself, rather than the actual networking.

I used Unity 2021.1.16f1 and got on average ~12 ms stopwatch time on both versions (located on the East Coast of the US). Test server is https://countries.trevorblades.com/, the zip file contains the Configuration already setup.

RPloutarchou commented 3 years ago

Thanks for the quick response, I will try using switching from Newtonsoft to JSONUtility to check if there is any difference and let you know.

NavidK0 commented 2 years ago

Closing for inactivity.