Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by ritesh_khokhani · Feb 11, 2014 at 10:27 AM · stringperformance optimizationstring comparison

Performace Overhit for String Concatenation in Online Pool Game Posted

Hi,

guys plz help me regarding long string concatenation!

i m making online pool game in which for pool ball movement sync to other players, i m broadcasting player(whoes turn is ) to other players and applying to other player balls!

when i m doing string concatenation i results in heavy performance overhit and ball jittering much! i m just sending data 10 times/second,

below are some code snippest i tried,

 StringBuilder sbData = new StringBuilder(10000);
 
         if (timeLastSending >= sendingPeriod) 
 
         {
 
             foreach(KeyValuePair<string, GameObject> kv in playerBalls)
 
             {
 
                 if(kv.Value.rigidbody.velocity.magnitude > 0.005f)
 
                 {
 
                     kv.Value.rigidbody.useGravity = true;
 
                     sbData.AppendFormat("{0:.000000},{1:.000000},{2:.000000},{3:.000000},{4:.000000},{5:.000000},{6},", 
 
                                                     kv.Value.transform.position.x, kv.Value.transform.position.y, kv.Value.transform.position.z, 
 
                                                             kv.Value.transform.position.x, kv.Value.transform.position.y, kv.Value.transform.position.z, kv.Key);
 
                     //print("SEND");
 
                     gameInstance.PlayerMoveMade(sbData.ToString());
 
                     sbData.Remove(0, sbData.Length);
 
                 }   
 
             }
 
             timeLastSending = 0;
 
             return;

i also tried for this one..

                 if(gameRulesScript.isGameStart && gameRulesScript.isSendBallData) // for the player whose' turn is
 
                 {   
 
                     for(short i = 0; i < 15; i++)
 
                     {   
 
                         if(balls[ballNo] != null)
 
                         {
 
                             balls[ballNo].rigidbody.useGravity = true;
 
                             data = string.Format("ball{0:D2},{1:.000000},{2:.000000},{3:.000000},{4:.000000},{5:.000000},{6:.000000},", ballNo + 1, balls[ballNo].transform.position.x, balls[ballNo].transform.position.y, balls[ballNo].transform.position.z, 
 
                                                                                                                                     balls[ballNo].transform.localEulerAngles.x, balls[ballNo].transform.localEulerAngles.y, balls[ballNo].transform.localEulerAngles.z);                
 
                             StartCoroutine("Move1");
 
                         }   
 
                         ballNo++;
 
                         if(ballNo > 14) ballNo = 0;
 
                     }   
 
                 }

on opponent side also when i m spliting it it takes lots of load !

please help me, is their any other better way so that this can be achieved at no performance overhit and game runs sooth like any other pool game!

Thankx!

Comment
Add comment · Show 3
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 theLittleSettler · Feb 11, 2014 at 10:56 AM 0
Share

Off the top of my head I can't think of a better method but two things come to $$anonymous$$d. Do you need 6 digit precision? The shorter the better. Also, cache balls[ballNo].transform so it doesn't need to read balls[ballNo] a half a dozen times. One other thought, how about converting the data to a bit stream?

avatar image ritesh_khokhani · Feb 11, 2014 at 06:48 PM 0
Share

thanks!

actually here 6 digit precision is needed for accurate position, i didn't get about caching of balls[ballNo].transform, can you please elaborate it?

i will try for conversation of sting to byte stream(as back end server supports byte format)!

avatar image theLittleSettler · Feb 12, 2014 at 09:04 AM 0
Share

Its a $$anonymous$$or thing but if you do: Transform ballTransform = balls[ballNo].transform; ... transform.position.x, transform.position.y etc Then the computer only needs to read the value stored in balls[ballNo] once (for each ball, each time that code is called). Come to think of it, the compiler might do it for you. But its good to know.

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

1 UI Text vs 2 UI Text 1 Answer

String.Equals returning false? 2 Answers

Grab part of a string by looking for keyword 2 Answers

How to extract part of a string variable? 1 Answer

Does Unity's Mono do a reference compare in its string == operator? 2 Answers


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