• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Dozer · Oct 23, 2010 at 09:48 PM · networkingwebplayeroptimizationwwwhttpwebrequest

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 t$$anonymous$$ngs 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 anyt$$anonymous$$ng 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, w$$anonymous$$le the HttpWebRequest is taking 47 ms - less than half of a tenth of a second!

Comment
BinaryCaveman

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Max Kaufmann · Oct 28, 2010 at 02:23 AM

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

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mikeytrw · Sep 20, 2011 at 12:55 PM 0
Share

Is there any way to avoid the encoding/processing?

It appears WWW is pretty inefficient.

avatar image

Answer by mikeytrw · Sep 21, 2011 at 10:39 AM

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 t$$anonymous$$s 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 w$$anonymous$$ch is pretty annoying.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Is HttpWebRequest supported for desktop and editor? 2 Answers

Is HttpWebRequest supposed to work in Web Builds or not? 1 Answer

Uploading a file is not working in Unity 2 Answers

Where to continue in Response/request? 0 Answers

Web build not calling WWW request 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges