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 catchthefloaty · Jun 10, 2013 at 08:07 AM · c#performancedictionary

need help getting more performance out of this thing

ok so i recently posted a make of HighLife(conways game of life) here: [url]http://forum.unity3d.com/threads/185340-HighLife-%28Conways-Game-Of-Life-Variation%29[/url]

it works wonderfully great. the issue of performance comes in when it reaches a cell count of about 5000. after profiling it comes down to one function that is slowing it down. im curious if anybody has any suggestions to make these functions faster. multithreading i beleive is an option as its not an unity api... but my attempts, if done correctly have shown no gain in fps.

that said this does get about 15 fps with 5000 living cells.

 public static void POKECELLS () {
         
         vectors = new List<Vector2>();
         foreach (Vector2 vector in cellDict.Keys) {
             vectors.Add(vector);
         }
         
         
         foreach (Vector2 vector in vectors) {
             cellDict[vector].pokeYourNeighbors();
         }
         
         
     }

which will call from each cell:

 public void pokeYourNeighbors () {
         
         //check 1-8 are Vector2 Objcts
         Master.POKE(check1);
         Master.POKE(check2);
         Master.POKE(check3);
         Master.POKE(check4);
         Master.POKE(check5);
         Master.POKE(check6);
         Master.POKE(check7);
         Master.POKE(check8);
         
     }

and then this last function :

 public static void POKE (Vector2 Position) {
         
         if ( cellDict.TryGetValue(Position, out cell)) {
             cellDict[Position].neighborCount++;
         
             
             
             return;
         }
 
         cellDict[Position] = new Ghost(Position);
        
         
     }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Loius · Jun 10, 2013 at 09:12 AM

Rip out an expensive array copy from poke cells:

 public static void POKECELLS () {
     foreach (Vector2 vector in cellDict.Keys) {
         cellDict[vector].pokeYourNeighbors();
     }
 }
 

p.s.: naming conventions are there for your safety; CamelCase for functions and classes and camelCase for variables will save many heartaches

Comment
Add comment · Show 3 · 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 catchthefloaty · Jun 10, 2013 at 02:17 PM 0
Share

it originally did that but the foreach loop makes celldict readonly, and the function edits that data.

avatar image catchthefloaty · Jun 10, 2013 at 02:53 PM 0
Share

an attempt to get around this by putting new ghost cells in a temporrary dict only made it slower . but the dictionry is altered in PO$$anonymous$$$$anonymous$$

avatar image Loius · Jun 11, 2013 at 07:20 AM 0
Share

ah, gotcha - you're doing that right, then, as far as i know. you just have to have a copy for this application.

for actions that will be repeated many times, cutting down function calls and news is a good first step in reducting time cost - it's ugly, but putting all the pokey functions into pokecells (ins$$anonymous$$d of separate functions) should add a small bit of performance

threading is a possibility but i'm not an expert on ti$$anonymous$$g safety; the threading i've done uses messages (sets a bool to true) to indicate that some data is ready to be read. following that pattern (which may be terrible), your thread would build the next frame and then pass tell the main thread to refresh its dictionary from the thread's working dictionary, while the thread creates a new working dictionary.

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

15 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

Related Questions

c# Adjust In-Game audio 1 Answer

C# Putting a Series of Labels in Between a Series of Buttons 1 Answer

C# Null Reference Exception in Custom Function 1 Answer

How to display a string without ToString 1 Answer

Trouble Understanding Vector3.Angle() Result 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