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

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

  • 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 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.

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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

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

Is HttpWebRequest supported for desktop and editor? 2 Answers

accessing sub directory perhaps an crossdomain error 1 Answer

Error with Facebook's crossdomain file? 0 Answers

Load Data From External Text File 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