太多的日志写入会降低Android应用程序的性能吗?
我想知道日志记录是否会降低应用程序性能? 另外,请给我一些提高 Android 应用程序性能的技巧。
I would to know whether logging can decrease application performance?
Also, please give me some tips to increase android application performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。过多的日志记录会影响任何应用程序的性能,而不仅仅是 Android。
开发人员指南建议您在发布之前停用并禁用日志记录:
因此,您应该抑制应用程序的“发布”或“生产”版本中的日志。
通过设置 debuggable 在 Android Manifest 中关闭它:
另一种方法
创建自己的记录器类并在执行日志之前检查调试模式。它允许调试模式和部署的应用程序之间的单点修改,并允许执行额外的操作,例如写入日志文件。
For further info read http://rxwen.blogspot.com/2009/11/logging-in-android.html
和 SO QA:
Log.d 和对性能的影响
Android 日志记录 - 如何清除以获得更好的性能
Yes. Excessive logging affects the performance of any application not just Android.
The developer guide suggests you to deactivate and disabled logging before release:
So, you should suppress the logs in "release" or "production" build of your App.
Turn off it in Android Manifest by setting debuggable:
Another way
Create your own logger class and check for debugging mode before executing log. It allows single point modification between debugging mode and deployed application and allows extra things to do such as writing to log file.
For further info read http://rxwen.blogspot.com/2009/11/logging-in-android.html
and The SO QAs :
Log.d and impact on performance
Android Logging - How to clear for better performance
在写入日志之前使用“if”语句。
您可以在应用程序发布时禁用日志。
例子 :
}
use 'if' statement before log writing.
you can disable log when application release.
example :
}
任何过多的文本输出都会减慢您的应用程序的速度,即使对于桌面应用程序也是如此。过多的日志记录确实会减慢速度,但您基本上需要发送大量数据,顺便说一句,使用 for 或 while 循环并不难做到这一点。有时记录时在后台发生的事情包括字符串操作、文本渲染、缓存管理、数据过滤、日志长度限制等等。
有多种方法可以从最终应用程序中删除 logcat,尤其是涉及 ProGuard 的方法。 ProGuard 不适合我,但是关于如何删除它们有很多绝妙的想法,包括像 sed 这样的脚本程序。
Any text output in excess will slow down your application, even with a desktop application. Excessive logging does slow things down, but you would basically need an insane amount of data being sent through, which by the way, isn't that hard to do with a for or while loop. Things that happen in the background while logging sometime include string manipulation, text rendering, cache management, data filtering, log length limiting, and the list goes on.
There's several ways to remove logcat from your final app, especially those involving ProGuard. ProGuard didn't work for me, but there's plenty of brilliant ideas out there on how to remove them including scripting programs like sed.