为什么 Java 的序列化比 3rd 方 API 慢? [英] Why Java's serialization slower than 3rd party APIs?

查看:68
本文介绍了为什么 Java 的序列化比 3rd 方 API 慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理套接字并通过它们序列化对象的过程中,我注意到有一些 3rd 方库可以在 Java 上更快地进行对象序列化,例如 KryoFST.到目前为止,我期望Java的序列化是优化的并且是最快的.因为,它依赖于语言,并提供了一个预计会更快的低级解决方案.但是,所考虑的库声称它们比 Java 快.

During working on sockets and serializing objects over them, I noticed that there are some 3rd party libraries for faster object serialization on Java such as Kryo and FST. Up to now, I expected that Java's serialization is optimized and the fastest. Because, it is language dependent and gives a low level solution that is expected to be faster. However, the considered libraries claim that they are faster than Java.

谁能解释为什么Java不能提供最快的序列化解决方案?为了什么而放弃更好的性能?

Can someone explain why Java could not provide the fastest serialization solution? For the sake of what does it give up a better performance?

提前致谢.

推荐答案

有几个原因(我是 http://code.google.com/p/fast-serialization/)

原因:

  • 爬上每个对象的类层次结构,对每个对象执行多次调用 read/writeObject 以防万一.
  • 部分编码不佳(已在 1.7 中改进)
  • 一些经常使用的类利用旧的、过时的序列化功能,例如 putfield/getfield 等.
  • 临时对象分配过多
  • 大量验证(版本控制、实现的接口)
  • 缓慢的 Java 输入/输出流
  • 设置/获取字段值的反射.
  • 使用需要大数字"(例如 Integer 或 Long)而不是原语的 JDK 集合.
  • 实现缺乏某些算法优化:-)
  • 基元在 x86 上被重新排序为网络字节顺序(在 Java 代码中,而不是本机).

为了提供更好的性能,他们将不得不放弃对旧版本控制方案的支持(例如 read/writeObject 当前的工作方式不是最理想的),并让一些诸如版本控制支持可选或选择对性能更敏感的方法来实现那(可能).此外,HotSpot 可能会添加一些内在函数来改进原语的低级处理.在设计 API 时需要考虑性能,而 JDK 序列化可能不是这种情况.

In order to give better performance, they would have to give up support of old versioning schemes (e.g. the way read/writeObject currently works is suboptimal), and make some things such as versioning support optional or choose more performance sensitive approaches to that (would be possible). Additionally HotSpot might add some intrinsics to improve low level handling of primitives. One needs to have performance in mind when designing an API, which was probably not the case with JDK Serialization.

这篇关于为什么 Java 的序列化比 3rd 方 API 慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆