Giter Site home page Giter Site logo

Comments (10)

Gracker avatar Gracker commented on August 26, 2024

没说的那么夸张吧...自己试试看看能不能接受.现在的手机配置都那么 NB

from android-open-project.

kainaer avatar kainaer commented on August 26, 2024

现在很多大型知名框架(比如Spring)中都大量用到了反射,新版本java反射性能也比以前提高了不少。你可以先用一下看看表现性能是否满意。 -- 发自 Android 网易邮箱 在2014年06月19日 11:39, zonda写道: 你好,我是 android 菜鸟一枚,冒昧的请教一个问题不知道是不是应该在这里发 issue 。Retrofit 是使用反射实现的动态代理,那会不会因为使用反射而影响 android app 的性能 ? google 了一下貌似 N 多的人说反射大大的影响 app 的性能,这让我倍感疑虑,求大神解答。 — Reply to this email directly or view it on GitHub.

from android-open-project.

Jayin avatar Jayin commented on August 26, 2024

现在手机没那么差吧(泛指现在4.0以上)

咦,发觉在issue里面讨论好玩好多。。要不在issue上弄个论坛啥的。。参考:https://github.com/jsconfcn/hangjs/issues

from android-open-project.

rengwuxian avatar rengwuxian commented on August 26, 2024

一丝都不会影响的,但看到有些人回答说是因为java反射的性能强,这是错误的,在此纠正一下。retrofit的原理是在初始化适配器的时候动态生成client对象,而在真正执行网络请求的时候是不需要使用反射的,这和guice的原理不一样,属于使用运行时反射的方式基本达到了编译时反射的效果,因此对于性能没有任何影响。
2014年6月19日 上午11:39于 "zonda" [email protected]写道:

你好,我是 android 菜鸟一枚,冒昧的请教一个问题不知道是不是应该在这里发 issue 。Retrofit
是使用反射实现的动态代理,那会不会因为使用反射而影响 android app 的性能 ? google 了一下貌似 N 多的人说反射大大的影响 app
的性能,这让我倍感疑虑,求大神解答。


Reply to this email directly or view it on GitHub
#31.

from android-open-project.

zondaOf2012 avatar zondaOf2012 commented on August 26, 2024

谢谢大家的解答~~

@kainaer 我可能不太认同“现在很多大型知名框架(比如 Spring )中都大量用到了反射”,我觉得客户端对响应速度的要求应该比服务端高,类似 Adapter 中的 HolderView 的成员变量不用 getXXX / setXXX 而是直接定义为 pulic,所以反射可能带来的性能影响应该还是要考虑的吧。

@rengwuxian 谢谢解答,“retrofit的原理是在初始化适配器的时候动态生成 client 对象,而在真正执行网络请求的时候是不需要使用反射的”,可能我对 Java 使用 Proxy + InvocationHandler 的动态代理理解得不够透彻了,“动态生成 client 对象 ”,最终不也是回调 InvocationHandler 中的 invoke 方法吗? 这个和一般反射的 invoke 方法有什么区别?

from android-open-project.

rengwuxian avatar rengwuxian commented on August 26, 2024

@zondaOf2012 首先向所有看到我上一条回答的人抱歉,我的回答是有问题的。Retrofit在请求的时候是使用了反射的,我一时昏头说错了却得到楼主的感谢,实在惭愧。昏头的具体原因就不解释了,我们专注问题。在Android 3.0之前,注解(Annotation)会有非常严重的性能问题。但后来已经被Google修复了。所以如果你的软件兼容到了Android2.3或者更早的版本,大量使用注解是会有性能问题的。但:1.问题是在于注解,而不是反射,虽然注解是基于反射的;2.显然Retrofit也大量使用了注解,可仍然没关系,因为Retrofit中注解只在初始化Client的时候被用到,一次初始化顶多也就几十上百个注解,而他的问题并没有严重到连这种读取量级的注解都会有明显卡顿的地步,所以,建议楼主放心使用Retrofit,很方便的啦~另外,我正在重度Github上的流行库,对Square和他的员工JakeWharton尤其感冒(Retrofit,OkHttp,Picasso,Dagger,ButterKnife,Scalpel,Madge,Otto,Timber),欢迎各位多交流!

from android-open-project.

zondaOf2012 avatar zondaOf2012 commented on August 26, 2024

@rengwuxian 恩,我现在也在研究 Retrofit,OkHttp,Picasso,Volley 这几个开源库,之所有一直纠结反射会不会影响性能这一点,是因为之前有看过 EvenBus 和 Otto 的对比, EventBus 声称他的响应比 Otto 要快。所以不自觉的又拿 Volley 和 Retrofit 对比,也看了一些 http://instructure.github.io/blog/2013/12/09/volley-vs-retrofit/ 但是感觉还是没有一个完美的答案。

from android-open-project.

rengwuxian avatar rengwuxian commented on August 26, 2024

@zondaOf2012 这片文章我去年纠结的时候也看了,当时对比了Retrofit,AsyncHttp,Volley之后,选择了Retrofit。不过我选择的理由不是性能,而是易用度和可扩展性。有兴趣的话我们QQ交流?这里讨论是不是不合适。

from android-open-project.

zondaOf2012 avatar zondaOf2012 commented on August 26, 2024

@rengwuxian 恩,好的。请问你的QQ是? 我的是764694958 ,有空多交流... ...

from android-open-project.

Trinea avatar Trinea commented on August 26, 2024

@zondaOf2012 @rengwuxian @Jayin @Gracker @kainaer 我建了个Q群 377723625,大家这里讨论吧

from android-open-project.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.