The price of ENUMs (100 Days of Google Dev)

By: Android Developers

699   38   47804

Uploaded on 08/25/2015

So what’s the deal with using ENUMs on Android? Some people say it’s bad, other people say it’s not a problem. What gives, and what’s the reasons?

To clear up some confusions, Colt McAnlis takes a look at the effect that enums have on your Android code size, memory footprint, and runtime performance.

Watch more Android Performance Patterns here: http://goo.gl/4ZJkY1

100 Days of Google Dev / 100 developer videos over 100 days / #GoogleDev100

Join the G+ Community here : http://goo.gl/g7mxmI

Subscribe to Android Developers: https://goo.gl/88dzea

#PERFMATTERS

Comments (6):

By anonymous    2018-04-08

@yole https://www.youtube.com/watch?v=Hzs6OBcvNQE (The price of ENUMs (100 Days of Google Dev))

Original Thread

By anonymous    2017-09-20

I follow a rule with enums in Android development:

  • if it has no params, use an intdef/stringdef,
  • if it has params, use an enum

If there is a way around using an enum, I'll certainly consider it where it doesn't undermine the code.

A lot was made from the video Colt Mcanlis posted: https://www.youtube.com/watch?v=Hzs6OBcvNQE&feature=youtu.be

however it had some fairly shaky numbers in it as pointed out by Jake Wharton: https://plus.google.com/+JakeWharton/posts/bTtjuFia5wm

The main drawback of enums is that they use more memory than constants would, but if that enum aids in better code, I say use it rather than micro-optimise. Just don't go overboard using them and be aware of their footprint.

Original Thread

By anonymous    2017-09-20

Firstly, you should avoid using enums in Android environment. Prefer to use @IntDef, @StringDef. The main reasoning behind this is the waste of resources. Enums take much more memory.

As Colt McAnlis shows in this perfmatters episode enums take 13x more space on rather trivial example.

Secondly, what you want to achieve may be done via Intents or Bundles, passing a boolean value from one component to another.

Original Thread

By anonymous    2017-10-01

My question has two part

1) Does Enum cause performance issue in Android as it says here Android Developers or it does not have much effect as it says here

I am really confuse should i use enum in my app or not

2) If I use enum in my app. What will be the best practice to save that enum in firebase

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.