如何快速序列化/反序列化复杂的java对象 [英] How to serialize/deserialize complex java object quickly

查看:84
本文介绍了如何快速序列化/反序列化复杂的java对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试和修复一个复杂的应用程序,它与一个巨大的 Java 对象(约 250M)一起工作.

I'm debugging and fixing a complex app, that works with a huge Java object (~250M).

我用另一个程序创建了这个对象.目前我使用 XStream 从硬盘加载和保存这个对象,但解析它需要一分钟多的时间.它减慢了开发过程.

I've created this object with another program. Currently I use XStream to load and save this object from the hard drive, but it takes more than a minute to parse it. It slows down the development process.

JAXB 更快吗?有没有其他方法可以加载和保存这个巨大的东西?

Is JAXB faster? Are there any other ways to load and save this huge thing?

推荐答案

在这种情况下,我会将数据序列化,这将使其更小更快.您可以外部化关键类以进一步提高速度.这是我最近做的一些测试 Protobuf vs Thrift vs Java序列化它与 kovica 建议的基准测试相同,但最近在更新的硬件/软件上运行.

In that case I would Serialize the data which will make it smaller and faster. You can Externalise key classes to improve the speed further. Here are some test I did more recently Protobuf vs Thrift vs Java Serialization Its the same benchmark as kovica suggest but run more recently on newer hardware/software.

如果你需要更快,你可以使用内存映射数据.这很难处理,但你无法击败性能.如果数据已经在磁盘缓存中,您可以加载 250 MB 是几十毫秒.如果不是,您将受到驱动器速度的限制,例如40 MB/s 的慢速驱动器大约需要 8 秒.

If you need to go faster you can use memory mapped data. This is much harder to work with but you can't beat the performance. You can load 250 MB is tens of milli-seconds if the data is already in disk cache. If not you will be limited by the speed of your drive e.g. a slow 40 MB/s drive will take about 8 seconds.

我编写的使用内存映射文件的库是 Java Chronicle

A library I wrote uses memory mapped files is Java Chronicle

这篇关于如何快速序列化/反序列化复杂的java对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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