x


Any way to speed up WWW requests?

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 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!

more ▼

asked Oct 23, 2010 at 09:48 PM

Dozer gravatar image

Dozer
46 9 6 12

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

WWW is also encoding the download into proper objects - are you accounting for the post-download initialization in your comparison?

more ▼

answered Oct 28, 2010 at 02:23 AM

Max Kaufmann gravatar image

Max Kaufmann
618 29 25 34

Is there any way to avoid the encoding/processing?

It appears WWW is pretty inefficient.

Sep 20, 2011 at 12:55 PM mikeytrw
(comments are locked)
10|3000 characters needed characters left

I've had some success increasing WWW request performance by building the POST data myself rather than using the WWWForm object:

     private string generatePostString(){
     
     //MW: Generate a random salt for this request
     System.Random random = new System.Random();
     int randomNumber = random.Next(0, 9999999);

     
     //MW: hash the salt and secret key
     string salt = randomNumber.ToString();
     string hashedKey = Md5Sum(mSecretKey + salt);
     
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     
     sb.AppendLine("hashedKey="+ hashedKey +"&salt="+ salt +"&deviceType=5&bindingVersion=0.1");
     
     foreach (DictionaryEntry item in mParameters){
         //MW: TODO We need to distinguish between data types and correctly handle each one.
         sb.AppendLine("&params["+item.Key.ToString()+"]="+item.Value.ToString());
     }
     
     return sb.ToString();
     
 }
 
 
 private byte[] convertPostStringToData(string postString){

     //MW: convert the string into a byte array
     ASCIIEncoding encoding = new ASCIIEncoding();
     return encoding.GetBytes(postString);
         
 }


Also, I suspect the additional time for a WWW request is because it has to load the crossdomain.xml for every request which is pretty annoying.

more ▼

answered Sep 21, 2011 at 10:39 AM

mikeytrw gravatar image

mikeytrw
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1500
x1196
x843
x798
x17

asked: Oct 23, 2010 at 09:48 PM

Seen: 2141 times

Last Updated: Sep 21, 2011 at 10:39 AM