High performance serialization: Java vs Google Protocol Buffers vs …?

前端 未结 7 1275
借酒劲吻你
借酒劲吻你 2020-12-04 08:05

For some caching I\'m thinking of doing for an upcoming project, I\'ve been thinking about Java serialization. Namely, should it be used?

Now I\'ve previously writt

7条回答
  •  我在风中等你
    2020-12-04 08:19

    For wire-friendly serialisation, consider using the Externalizable interface. Used cleverly, you'll have intimate knowlege to decide how to optimally marshall and unmarshall specific fields. That said, you'll need to manage the versioning of each object correctly - easy to un-marshall, but re-marshalling a V2 object when your code supports V1 will either break, lose information, or worse corrupt data in a way your apps aren't able to correctly process. If you're looking for an optimal path, beware no library will solve your problem without some compromises. Generally libraries will fit most use-cases and will come with the added benefit that they'll adapt and enhance over time without your input, if you've opted for an active open source project. And they might add performance problems, introduce bugs, and even fix bugs that haven't affected you yet!

提交回复
热议问题