自动生成 JavaExternalized readExternal() / writeExternal() 块

发布于 2024-11-29 16:14:59 字数 418 浏览 4 评论 0原文

我正在开发一个项目,其中 Java 的本机序列化速度很慢,因此我们希望在类上实现Externalize 接口以获得卓越的性能。

然而,这些类有很多数据成员,我们已经意识到在编写这两个方法时很容易出错。我们只是在这些函数中读取/写入类的所有成员,没什么花哨的。是否有某种方法可以在离线过程中或在编译时自动生成 readExternal() writeExternal() 块以进行外部化?

我查看了 http://projectlombok.org/,类似的东西是理想的。

类似地,我们希望保持这些类不可变,但不可变类不能实现可外部化接口 - 我们希望使用有效 java 中的代理类模式 - 生成它也会很有用。

I am working on a project where Java's native serialization is slow, so we want to move to implementing Externalize interface on the classes for superior performance.

However, these classes have lots of data members, and we have realized its easy to make mistakes while writing these two methods. We are just reading/writing all of the members of the class in these functions, nothing fancy. Is there some way of generating the readExternal() writeExternal() blocks for externalize automatically in an offline process, or at compile time?

I had a look at http://projectlombok.org/, and something like that would have been ideal.

Similarly, we would like to keep these classes immutable, but immutable classes can not implement the externalizable interface - we want to use the proxy class pattern from effective java - having that generated would be useful too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老娘不死你永远是小三 2024-12-06 16:14:59

我正在开发一个项目,Java 的本机序列化速度很慢

有多慢?为什么?从长远来看,通过大量手工编码来提高速度在经济上是可行的,也不太可能是可维护的。序列化开销实际上应该归结为传输中的时间和空间限制。没有什么特别的原因可以解释为什么 Java 的默认序列化比您计划的所有手工编码的结果慢得惊人。你最好调查一下原因。例如,您可能会发现放置得当的 BufferedOutputStream 可以解决您的所有问题。

I am working on a project where Java's native serialization is slow

How slow? Why? Making it faster with lots of hand coding is most unlikely to be either economically feasible or maintainable in the long run. Serialization overheads should really come down to time and space bounds in transmisssion. There's no particular reason why Java's default serialziation should be startlingly slower than the result of all the hand coding you are planning. You would be better off investigating causes. You might find for example that a well-placed BufferedOutputStream would solve all your problems.

安静 2024-12-06 16:14:59

关于 Project Lombok 它拒绝了该功能

我会考虑利用替代框架:

  • SBE - 用于金融交易;
  • kryo 项目 - 用于 Java 兼容性;
  • FlatBuffers - 用于惰性零拷贝解析和跳过嵌套结构的能力;
  • Protobuf - 比平面缓冲区更紧凑,但在随机访问区域中缺少解析(可能在平面缓冲区中,例如在内存映射文件上)。

Java 序列化在吞吐量、大小、可移植性和模式迁移方面都非常低效。

MapStruct - 如果需要,可以是将可变内容映射为不可变内容的不错选择最少的自定义代码(和 IDE 支持)。

Regarding Project Lombok it's rejected the feature.

I'd consider leveraging alternative frameworks:

  • SBE - for financial transactions;
  • kryo project - for Java compatibility;
  • FlatBuffers - for lazy zero copy parsing and ability to skip nested structures;
  • Protobuf - bit more compact than flat buffers but missing parsing in random access regions (possible in flat buffers e.g. on memory mapped files).

Java serialisation is very inefficient both throughput, size, portability, and schema migration.

MapStruct - can be good option to map something mutable into immutable if required with minimum custom code (and IDE support).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文