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 jjennings1990 · May 22, 2014 at 06:50 PM · saveperformance optimizationbytes

Issues with memory stream or File saving potentially affecting performance?

Hello all I am working on a project where I am saving and storing a lot of to mobile devices. roughly 10 megabytes of of JSON Data converted to a string and stored in player prefs and converting a float array to bytes data and storing those bytes in a directory in the persistent data path .

I have checked and re-checked my code and all the lists and objects we are using to store and track the data are being de-allocated yet whenever we write the audio bytes to our memory stream we gradually see performance drops.

the amount of data isn't even the problem , it takes 6 save attempts before the performance drops so far that the project is basically paused . and this rung true for 6 5 second playbacks the same it did for 6 1 minute playbacks .

I just wanted to know if anyone who has done something similar has seen such performance drops and if there are any known ways to rectify the issue ? below is some code of my save process as it is now .

string audioClipName ="Slot"+pslot.ToString()+ "clip" + L.ToString(); string filePath = "";

         if(Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
         {
             //*** Here we create a file path based on combining our file name with our data path
             filePath = Path.Combine(Application.dataPath ,audioClipName);
             
             // if this file exists , we read the existing bytes 
             if(File.Exists(filePath)){
                 //*** we remove pre-existing data
                  System.IO.File.Delete(filePath);
                 
             }
             //else if unity is currently on an iphone or android device  , load bytes from the persistent data path 
         }else if(Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android){
             
             //*** Here we create a file path based on combining our file name with our data path
             filePath = Path.Combine(Application.persistentDataPath ,audioClipName);
             
             // if this file exists , we read the existing bytes 
             if(File.Exists(filePath)){
                 //*** we remove pre-existing data
                  System.IO.File.Delete(filePath);
                 
             }
         }

         //yield return new WaitForEndOfFrame();

     bytes = ConvertFloatsToBytes(audioFloatData);

         DebugTools.Log(" converting bytes to float ");
     yield return new WaitForEndOfFrame();
         
     System.IO.File.WriteAllBytes(filePath,bytes);
         DebugTools.Log(" Saved bytes ");


We use the yield statements to give a brief pause in between actions, we thought running intensive process immediately after intensive process was possibly making the save flow even more processor intensive than it had to be .

I nearly included the playerprefs save functionality but I honestly don't think that's where the performance drop is coming from . I haven't done much save functionality so any and all advice or resources are appreciated.

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 rutter · May 22, 2014 at 07:34 PM 0
Share

File operations tend to be slow, especially if you're reading or writing a large number of bytes. If you can't split those I/O operations into smaller pieces (for example, handling a few bytes per frame rather than all of them at once), you might try waiting until there's a lull in the gameplay, perhaps when switching levels or some such time.

avatar image jjennings1990 · May 28, 2014 at 11:00 PM 0
Share

Unfortunately our entire game takes place in primarily one scene but I actually will take a look into breaking down the byte writing into separate smaller sections , that's a fantastic suggestion , Thank you !!!!

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

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

Related Questions

unexpected char: 'U'. when File.WriteAllBytes() 2 Answers

How to save/load the Y-Coordinates of Instantiated Objects 1 Answer

Best way to save procedural world/mesh? 0 Answers

How to modify or save xml on Android 0 Answers

Save and load data with Javascript... 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