Search Unity

Comparing performance of HttpWebRequest to WWW class

Discussion in 'Scripting' started by Zelek, Oct 23, 2010.

  1. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    I'm moving a multiplayer application of mine from XNA over to Unity so that I can make use of the web player. To make things work with the Web Player, it seems I have to use the WWW class instead of HttpWebRequest. My tests are showing that accessing the exact same page from in a Unity application takes 10 times longer using WWW than it does using HttpWebRequest. Is that to be expected? Is there anything I can do to improve WWW's performance?

    In my specific case, the WWW request takes about 450 ms (around half a second) to fully execute, while the HttpWebRequest is taking 47 ms - less than half of a tenth of a second!
     
    Last edited: Oct 23, 2010
  2. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    Any ideas would be appreciated.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    No you can't do anything to improve it. its also not needfully a WWW thing because you compare apples with eggs here as xna does not exist on mono and unity does not use nor support MS .NET ... the two compilers are half a world appart ...
    in addition, on the webplayer, you must not forget the crossdomain impact (you would need to use silverlight to even remotely fair compare there)
     
  4. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    Well, even forgetting XNA entirely, the issue can be restated as:
    Using the HttpWebRequest class in Unity is ten times faster than using the WWW class to access the same remote page. I'm curious why this is.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Functionality

    a HttpWebRequest does not load the sounds to use, does not load the texture to use and does not load the asset bundle to load and aside of texture you couldn't load any of this out of the data a httpWebRequest generates as they can not be loaded from byte. So even in a standalone, the only place you can use the webrequests, you would end on another WWW for the sake of it

    did you ensure to compare with a plain pure text page to prevent the media asset related handling to kick in?
    Also, WWW should bound to the thread priority, which will likely have an impact as well (unsure on the inner working on the HttpWebRequests here).
    Also, from what I recall, WWW is actually directly on the tcp socket, not other functionality, on standalone players for win / osx (the webbrowsers http networking stuff on browsers, NSURLConnection on iOS etc)