RestSharp dependency, Events, and performance

Editor
Jul 3, 2013 at 12:12 AM
Edited Jul 3, 2013 at 12:26 AM
Earlier we talked about removing the RestSharp dependency. I did some testing today, and I don't see any significant performance difference. Removing RestSharp does mean we'd need to add the Microsoft HttpClient Library (because HttpClient is included in 4.5, but not 4.0 which we're targeting). I think it's better to have a dependency on a Microsoft package than a third-party one, but really, meh. I could go either way.

However, in my testing, I did notice that it's taking us a full minute to return a GetAllEvents response. I tested this in the main branch to make sure my async changes weren't doing it. The result (using a Release build):

Elapsed Time: 56745
Total Number of Events: 84277

If you go to your browser and you just type in http://api.guildwars2.com/v1/event_details.json, the response comes back instantly. So why, when we do this in our code, does it take so long?

The answer is GwEvent.ResolveIDs(). It's spending that whole time resolving IDs and returning the new objects. This brought me back to the fact that GwEvent is a struct. I flipped it to a class, and this was the result:

Elapsed Time: 30673
Total Number of Events: 84272

It literally cut the time in half - just changing the word 'struct' to 'class', with no other changes.

Now, if we make it a class, then we also don't have to do ResolveIDs at all. We can just expose Map, Name, etc as property accessors that do the lookup. I changed the class to work like that, and this was the result:

Elapsed Time: 2640
Total Number of Events: 84318

So we're down from one minute to 2.6 seconds.

Please, please, can we stop using struct for events. The object is just too complicated. It's horrible for performance, and it's making our wrapper unusable for any high performance application.
Coordinator
Jul 5, 2013 at 6:38 PM
I'll think about it.
However the events is something we have to look at regardless of the struct vs. class discussion. Anet changed their API and exposed more details via the event_details.json method. Currently I'm a bit busy with my exams (here in Germany our exams are at the end of July).

I'll try to increase the performance with the next few releases.

Also do we really need the HttpClient, or couldn't we just use the WebClient instead?
Editor
Jul 5, 2013 at 6:47 PM
Actually the new event_details.json call is easy to deal with. It's just another huge cacheable list like the event names. The data in it doesn't change. So we just deserialize that into a list and expose properties off the current GwEvent object that looks up those values when requested. This is easy to do when it's a class rather than a struct.

I went ahead and checked in the 2.6 second version of EventData and GwEvent in the main branch. The performance of the old one was just unacceptable.

I haven't looked into using WebClient. It seems everyone uses HttpClient, probably just because it's so easy.
Coordinator
Jul 5, 2013 at 7:31 PM
I know that and most of the code is still in place. However there were some minor bugs and I didn't check it in for that reason. I'll look up your code and see what we can do about it.

Also, I don't really care if we use Rest# or the MS Library.