Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by laurG · Feb 11, 2019 at 08:29 PM · optimizationgarbage-collection

Zero Garbage Policy

Hey,

I'm starting a new project in which I want to really focus on performance. One of my policies for this project is "Zero Garbage".

So I setup a project and implemented a few things that seem to run flawlessly. I bring in the profiler and I get a lot of garbage from Unity under the hood.

I was planning on using the Lightweight scriptable pipeline, but it was generating 2Kb of garbage each frame with a very simple scene with about 5 objects (2000 faces at most).

Few more whacky workarounds for some other garbage generated under the hood (like adding the obsolete GUILayer on Camera, which for some reason will stop generating 0.8Kb of garbage each from from Mouse SendEvents or something like that).

At the moment I'm trying to figure out how to get rid of these 17 bits: alt text

Is this something attainable? Or should I just give up on getting rid of all the garbage generated "by default"?

Thank you!

1.png (78.6 kB)
Comment
Add comment · Show 1
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 Bunny83 · Feb 12, 2019 at 12:46 PM 1
Share

Note that some of the garbage is editor related. There is an "editor feature" that GetComponent will always return an actual object, even when no component was found. Unity does not return null but a fake null object in order to display a more clear error message when that null reference is used. However that means everytime you use GetComponent with a non existing component, you will allocate a new fake null object.


Though as i said this only happens in the editor. Yes, it's annoying and can't be worked around at the moment. However you can get rid of this by creating a development build and use the profiler on that build just as the documentation suggests. Search for "build" on that site to quickly find the relevant section(s).


edit

Oh, I haven't used it myself yet, but you may be interested in the "garbage free string system" gstring from @vexe . Note that this doesn't help you with any Unity properties or methods that return a string (like obj.name, obj.tag) but it helps with your own string generation.


Another quite useful page is this Unity tutorial about garbage optimisations

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by kaarloew · Feb 12, 2019 at 08:11 AM

I would think that currently it is not possible to get to zero garbage in any reasonable way, since there are many .NET and Unity methods that allocate and release memory dynamically. But the situation is getting better since e.g. Span<byte> is making things more efficient.
https://msdn.microsoft.com/en-us/magazine/mt814808.aspx

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 laurG · Feb 12, 2019 at 10:15 AM 0
Share

Thanks. Seems like a good read. Will make time for it tonight.

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

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

Related Questions

How do I efficiently maintain a constantly-changing list without triggering GC? 2 Answers

SendMouseEvents - GC Collect Spike Issue 1 Answer

Display numbers in UI.Text Garbage Free? 2 Answers

Questions About Allocations - Arrays - Structs and so on 1 Answer

Does writing to Mesh arrays cause allocation? 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