question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] Use enumerated annotations instead of enums

See original GitHub issue

Given how inefficient enums are on Android, would it be possible to leverage enumerated annotations instead of generating plain Java enums?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
futtetennistacommented, Nov 11, 2016

I’m not working on a project that involves Thrift on Android atm so I won’t be able to try it in the near future. But thanks a lot for implementing it.

On Fri, 11 Nov 2016, 02:15 Ben Bader, notifications@github.com wrote:

@futtetennista https://github.com/futtetennista I don’t know if you’re still interested in this feature, but I slapped it together just now. It’s available to play with at https://github.com/benjamin-bader/thrifty/tree/int-enums. I’m probably not going to publish this as a snapshot soon; it’s such a far-reaching change that the current test setup can’t do both Java and IntDef enums.

If you do try this out, I’d be curious what it does to your total method count and to your .dex size. My suspicion is that it won’t do much, due to the helper classes. If we decided to forego string names, that would change things considerably.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Microsoft/thrifty/issues/20#issuecomment-259855659, or mute the thread https://github.com/notifications/unsubscribe-auth/AATuwz8hwtw1i6xq_9PrGZzQ6HTUKKGZks5q88GogaJpZM4H1Ds2 .

1reaction
benjamin-badercommented, Mar 22, 2016

My understanding is that the ~1.5kb “memory penalty” for enums happens per declaration

Hmm, maybe I misunderstand. I’m thinking that quite a bit of that 1kb comes from the base class and associated code, which (thanks to object orientation) are shared across declarations. Certainly, methods like Enum#values() get deduplicated during dexing.

As you say, it’s not exactly the case that using a few enums will ruin your app. I still hold the belief that the safety provided by enums outweighs their cost on-device. I certainly wouldn’t use such a feature as int-enums myself, but wouldn’t say no to having an option (non-default) to generate them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ENUMS VS ANNOTATIONS IN ANDROID. In ... - Anmol Sehgal
In android enums are not considered as a “Best-practise” to be used because of memory issues, as every enum type is an object...
Read more >
Java Enums and Annotations Best Practices
1. Use enums instead of int constants. An enum type is a special data type that enables for a variable to be a...
Read more >
How and when to use Enums and Annotations
In this part of the tutorial we are going to cover yet another two great features introduced into the language as part of...
Read more >
How to supply Enum value to an annotation from a Constant in ...
Actually in order to use in a @RolesAllowed notation you would have to reference the value, NOT the enum. Example: @RolesAllowed({ Gender.Constants.MALE_VALUE }) ......
Read more >
Enums & Annotations - The Java Interview Handbook
Use EnumSet instead of bit fields to efficiently store enum values of the same type. Methods in an EnumSet are implemented using arithmetic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found