开发者

Guice Performance on Android

As a Java developer I've become accustomed to having dependency injection available in applications. For Android though, I am especially wary of performance. What are the performance implications for using Guice in an Android app? I assume there is some overhead, but is it significant enough that I should avoid usin开发者_开发技巧g Guice?

My use of it would likely just be to inject a few shared objects into various activities.


I would avoid using DI in android as google suggests: http://developer.android.com/training/articles/memory.html#DependencyInjection

Dagger solves some timing problems but still wastes memory for no real benefit.


As of version 3, Guice caches reflective objects to improve performance. There's at least one bug out against dalvik to make annotation lookups faster, but the current performance is workable.


Roboguice (and Guice) can significantly degrade app startup time. My moderately sized and not-yet-complete app took almost 15 seconds to start on an HTC EVO 4g.

Take a look at Dagger as an alternative that should provide virtually no startup overhead.


You should definitely use Dagger 2 for Android projects if you're concerned with performance.

Dagger 2 does not use reflection to scan your app’s code. Dagger’s static, compile-time implementation means that it can be used in Android apps without needless runtime cost or memory usage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜