简体   繁体   English

具有长类和字段名的Java默认序列化

[英]Java default serialization with long class and field names

my question is, how does java serialisation work? 我的问题是,java序列化如何工作? I'm serializing 100_000 objects of a class with a long class name and long field names. 我正在使用长的类名和长的字段名序列化一个类的100_000个对象。 And it takes much more time then with another class with short class/field names. 与使用简短的类/字段名称的另一个类相比,这需要更多的时间。 So does java serialization write the class and the field names with every object? 那么Java序列化是否会为每个对象编写类和字段名称? Or maybe just the field names with every object? 或者只是每个对象的字段名称?

Java writes the class descriptor once for each class in the serialization stream. Java为序列化流中的每个类编写一次类描述符。 The class descriptor includes the class name, the field names, and the class names (or references to class names) of the field types. 类描述符包括类名称,字段名称和字段类型的类名称(或对类名称的引用)。

The class descriptor for an object is embedded in the object for the first object of that class in a stream. 对象的类描述符嵌入到流中该类的第一个对象的对象中。 Subsequent objects of the same class only contain a reference to the class descriptor. 同一类的后续对象仅包含对类描述符的引用。

Field names only appear in the class descriptor. 字段名称仅出现在类描述符中。 The object's field values are represented as an array of values; 对象的字段值表示为值的数组; no names. 没有名字

It is likely (though not obvious from the spec) that class and field names in class descriptors are de-duped. 类描述符中的类和字段名称可能会被重复数据删除(尽管从规范中并不明显)。

For more details, refer to the Object Serialization Stream Protocol specification. 有关更多详细信息,请参阅对象序列化流协议规范。


This means that long class and field names will make a serialization longer, but there should not be significant repetition of the names. 这意味着长的类名和字段名会使序列化时间更长,但是名称的重复不应太多。

It takes much more time then with another class with short class/field names. 与使用简短的类/字段名称的另一个类相比,这要花费更多的时间。

That is surprising if (as you seem to be saying) you are putting 100 objects of the same class into a stream. 如果(正如您似乎在说的那样)将100个相同类的对象放入流中,这是令人惊讶的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM