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 robinking · Aug 05, 2010 at 11:50 AM · javascriptperformanceresizebuiltin array

Resizing builtin arrays

I'm using arrays which must be accessed many times every frame, so I'm using builtin arrays. However I often need to resize these arrays, remove entries, add entries etc. I know you can do it with js arrays but they are much slower. As I see it I have two options:

// Using only builtin arrays function DeleteThingUsingOnlyBuiltin(index) { // check that index exists in the array, if not return null if (index >= thingCount) { return null; } thingCount--; var thingPositionTemp = bPos; thingPosition = new Vector3[thingCount]; for (var i=0;i<thingCount;i++) { var ii; if (i<index) {ii=i; } else {ii=i+1; } thingPosition[i] = thingPositionTemp[ii]; } }

// Using JS arrays function DeleteThingUsingJSArray( index : int ) { // check that index exists in the array, if not return null if (index >= thingCount) { return null; } thingCount--; var jsArray = new Array (thingPosition); jsArray.RemoveAt(index); thingPosition = jsArray.ToBuiltin(Vector3); }

The JS version is neater and easier to implement (especially as there are more attributes than this in the actual code), but is it going to slow me down significantly compared to the purely builtin version? I will still do all my array ACCESSING through builtin arrays.

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

2 Replies

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

Answer by Eric5h5 · Aug 05, 2010 at 11:46 PM

Using generic Lists is faster than dynamic arrays. Javascript has generics in Unity3, so it's possible to use them now if you have access to the beta. A static built-in array will always be faster since there's less overhead, so if you really need to get every last bit of speed possible at the expense of convenience, then stick with built-in arrays. But Lists are fast enough in many cases where Arrays are too slow.

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
avatar image
1

Answer by jashan · Aug 05, 2010 at 12:33 PM

To be honest, as long as it's just once per frame and not for hundreds or thousands of objects, I wouldn't worry too much about performance. When you're on the iPhone, things look different, of course.

Personally, I avoid using arrays as much as possible and use proper generics classes (List) as those are much more convenient to use. Internally, those use arrays most of the time and handle the "adding stuff to the list / removing stuff from the list" efficiently for me.

Have you done any performance comparison between the different types of arrays? That will probably show you if it's worth the hassle at all. You can't use generics in JavaScript, so don't worry about those ...

Comment
Add comment · 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 robinking · Aug 05, 2010 at 01:14 PM 0
Share

It would be quite a bit more than once per frame unfortunately... and I script in UnityJS, so I'm guessing the Lists are out?

I did a bunch of stuff in builtin arrays, then converted to completely use JS arrays and it ground to a halt.

Assu$$anonymous$$g performance is critical, is option 1 in my question going to be faster than option 2? Even if it's $$anonymous$$imal, it will all add up.

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

No one has followed this question yet.

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

How do I change the size of a UI Image? (Javascript) 0 Answers

Performance Optimization ~Function Update: Loop or Once ? 5 Answers

OnMouseDown ect have effect on iPhone Build? 3 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