frankiesardo / icepick

Android Instance State made easy
Eclipse Public License 1.0
3.75k stars 208 forks source link

Question: does using this library affects performance? #80

Closed AndroidDeveloperLB closed 8 years ago

AndroidDeveloperLB commented 8 years ago

I ask this because on the one hand, you wrote " It uses annotation processing to generate code that does bundle manipulation and key generation" , yet on the other hand, you wrote it needs proguard rules. If it creates the code while building, why does it need protection of code?

How does it work?

livotov commented 8 years ago

it does not affect app performance at all as it generates the code at compile time instead of scanning classes and doing reflection work at runtime (which is slow)

proguard rules are needed to avoid generated classes obfuscation, not for protection. If you do not use proguard in your app - you have nothing to tweak.

frankiesardo commented 8 years ago

Excellent answer @livotov 👍

AndroidDeveloperLB commented 8 years ago

Cool. But if it's auto-generated, why do I need to add functions, instead of just the annotations?

In "Activity", for example, why do I have to call Icepick.restoreInstanceState(this, savedInstanceState); and Icepick.saveInstanceState(this, outState); ?

Can't it auto-generate this code, by checking if there is an implementation of "onCreate" and "onSaveInstanceState" , and add the code accordingly?

Is it possible?

frankiesardo commented 8 years ago

@AndroidDeveloperLB Those functions are used to link the generated code to the hand written one. Note that icepick is not adding code to classes that you've written: it's generating entirely new classes. To do what you propose you'd need to perform bytecode injection which is way over the top for a simple use case like this.

AndroidDeveloperLB commented 8 years ago

So auto-generating classes is easier than adding code to existing ones? I wonder then, does Google inject code in any of its libraries ?

livotov commented 8 years ago

@AndroidDeveloperLB Annotation processing api does not allow to preprocess and modify the existing source code (one you wrote in IDE), it only allows to generate new standalone classes. That's why you have to put a bit of manual work like Icepick.saveInstanceState(...)

AndroidDeveloperLB commented 8 years ago

So I see. Does Google inject code ?

frankiesardo commented 8 years ago

Ask Google

AndroidDeveloperLB commented 8 years ago

haha I was just curious.