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 sssss53 · Mar 19, 2015 at 12:49 PM · listruntimedictionarydesign

Dictionary and List Efficiency Issues

So in the game I'm working on I have a dictionary with information of all the characters. The key is the name of the character, and each corresponding value has a type of Info, which is a custom class I made myself containing a bunch of properties of that specific character.

In the class Info, there're basically two types of properties: one is more like independent, something I need to hardcode like the character description - and I'm loading them from a config file; while the other is more like dependent, like you can calculate them when you use this instance of Info.

What I'm doing right now is that I'm constructing the dictionary inside Awake() with only the second type of the properties. But in order to fill in the other information in the dictionary, I load everything I need from the config file as a List, and then go through the list and push the missing info into the dictionary. With this O(n), I actually have to go through a dictionary first and then a list.. So I'm not sure if there's a better practice out there..

The other option I can think of is that I only construct the dictionary with info from config file first, and not calculating the other info until the character is in use, which is more like I calculate it at runtime.

I'm not sure whether I'm overthinking or not. I've been struggling with it for a night and have no idea like does it really matter and if so, which one is better?

Sorry for the lengthy question and any help would be appreciated here.

Comment
Add comment · Show 2
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 AlwaysSunny · Mar 20, 2015 at 06:30 AM 2
Share

You're probably talking about milliseconds anyway. If this is behind a loading screen, it's unlikely to make much difference. Reading the file might even represent a greater time-cost than doing the extra work involved in your method. Unless you're doing sorts or other costly operations as you go, I would make it work in the most convenient, readable manner possible and slate it for refactoring in the "if I get around to it" pile.

avatar image Nymisu · Mar 20, 2015 at 09:59 AM 2
Share

This would be a performance problem on a 486 or lower computer. Don't bother with premature optimization. If it runs at above 30fps in the editor, everything is perfectly fine. Start thinking about whether or not it should run better and faster when the game jerks or freezes when certain scripts are executed.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sssss53 · Mar 20, 2015 at 12:35 PM

AlwaysSunny and Nymisu, thanks guys! I think you're right. I'll get it done first anyways. You just remind me of that famous

Premature optimization is the root of all evil.

Never thought of myself doing the same evil when I actually come down to that point :') Thanks again!
Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Quickly access specific list elements in a constantly changing list 1 Answer

An element with the same key already exists in the dictionary 0 Answers

Changing Custom Object Variable 1 Answer

Creating a UI list at runtime programmatically 0 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