News for hackers. Stuff that matters.
Re:Fury: 170x faster than JDK, blazing fast serialization by... by npstr on Sunday October 08, 2023 @07:28AM (#37809594)
The comparison to JDK serialization is surprising me. Noone should be using it for anything serious in production. Even the Chief Architect of the Java platform has called it a "horrible mistake". https://www.infoworld.com/article/3275924/oracle-plans-to-du...
Re:Fury: 170x faster than JDK, blazing fast serialization by... by chaokunyang on Sunday October 08, 2023 @07:38AM (#37809626)
There are too many java serialization libraries, I compared fury with jdk/kryo/fst/protostuff/protobuf/flatbuffers/thrift/msgpack/canproto/acro/jackson/json. Fury are fastest too. See https://github.com/eishay/jvm-serializers/wiki for detailed benchmark results.

It's a hard choice to select one for the title, so I use JDK for it, which may be not a good choice.

BTW, fury support jit serialization for jdk17 record, which is super fast compared to other serialization frameworks such as kryo

Re:Fury: 170x faster than JDK, blazing fast serialization by... by pron on Sunday October 08, 2023 @08:04AM (#37809741)
Just to be clear, though, the mistake that Mark Reinhold refers to isn't the particular implementation of the JDK's core serialization, but the design that allows arbitrary objects to be deserialized while bypassing their constructors (and so their established invariants). Unfortunately, many other serialization libraries — faster or slower — are repeating the same mistake. I.e., any serialization library that can serialize any class that implements Serializable suffers from all the same flaws of core serialization.

Correct serialization can only be done for classes that are designed for it by having a well-known construction protocol, which are currently basic collections, enums, Strings, records, and classes that register specific serialization code.

Re:Fury: 170x faster than JDK, blazing fast serialization by... by chaokunyang on Sunday October 08, 2023 @09:35AM (#37810327)
I see, totally agreed! If any objects can be serialized, the deserialization will introduce security issue. For example, `constructor/equals/hashCode` may contains malicious code, which introduce the deserialization risks.

Fury put much work on this to avoid the open dynamic deserialization risks.

But although `basic collections, enums, Strings, records, and classes that register specific serialization code` are the only objects should be allowed for serialization, and they are serialized by the construction protocal. There are so many applications has used the existing serialization protocol assumption, we have to keep compatible, otherwise most of existing application can't use fury.

Re:Fury: 170x faster than JDK, blazing fast serialization by... by mkleczek on Sunday October 08, 2023 @10:16AM (#37810639)
Why?

Zero copy state transfer is a viable and high performance alternative.

Security and integrity can (should?) be implemented at a different layer.

Re:Fury: 170x faster than JDK, blazing fast serialization by... by chaokunyang on Sunday October 08, 2023 @10:46AM (#37810929)
Not exactly. For java serialization, you can serialize java native object directly without define dsl and compile the schema, which are mush more easy to use. But it also means the deserialization will need to create the user-defined class, which may contains malicious coode in `constructor/queals/hashCode`. So the security can't be done at a different layer unless you are in a intra-net which no attack will happen which may be implemented at a different layer but we can't ensure that.

The

Re:Fury: 170x faster than JDK, blazing fast serialization by... by chaokunyang on Sunday October 08, 2023 @10:49AM (#37810958)
We must realize there always a tradeoff here. If you define a dsl for serialization data and generate the code like protobuf, the security issue will be much less. But it comes with the cost. Protobuf generated class are not the domain class, and can't be used for domain-driven application developemnt, and it doesn't support circular references too. What fury does it provide better performance and provide better usability.
Re:Fury: 170x faster than JDK, blazing fast serialization by... by mumblemumble on Sunday October 08, 2023 @01:01PM (#37812264)
> Zero copy state transfer is a viable and high performance alternative.

Completely agreed, but also, adding my own emphasis there.

The technique has has enough gotchas, edge cases, and additional security considerations that it should really be an alternative that people can opt for when they need it, and never be the default approach.

Re:Fury: 170x faster than JDK, blazing fast serialization by... by chaokunyang on Sunday October 08, 2023 @11:17PM (#37816581)
Yes, it should be an alternative. In fury, we disabled it by default, and all those benchmarks doesn't enable it. Most objects are value bounded, not binary data bounded. Zero-copy won't have a big speed up too. But if the objects graph has many ByteBuffer/Tensor/DataFrame/ArrowTable, then the zero-copy will have a big leap. see python pickle5 out-of-band serialization to speed up pandas/numpy as an example
Re:Fury: 170x faster than JDK, blazing fast serialization by... by pron on Sunday October 08, 2023 @05:14PM (#37814480)
But the only reason core serialization is considered a "horrible mistake" has nothing to do with performance or with any aspect of the technical implementation. It is considered a mistake only because serialising arbitrary classes breaks invariants in a way that has serious correctness and security implications.
Re:Fury: 170x faster than JDK, blazing fast serialization by... by mkleczek on Sunday October 08, 2023 @05:41PM (#37814663)
The point is that security and bypassing constructors are completely orthogonal as serialisation by memcpy is completely viable strategy and is no less secure than calling constructors on objects.
Re:Fury: 170x faster than JDK, blazing fast serialization by... by pron on Sunday October 08, 2023 @08:07PM (#37815569)
Whether or not they're orthogonal, it is that aspect that we talk about when we talk about the mistake of core serialization in the JDK. Also, whether calling constructors is necessary for security depends on many details. When we talk about fixing serialization in Java, we talk about a design that is independent of the format used for the serialized data. I understand you're that this is a different layer from the one you're interested in, but that is the layer where the mistake was made, and so that is the layer that requires fixing.
Re:Fury: 170x faster than JDK, blazing fast serialization by... by mkleczek on Monday October 09, 2023 @12:14AM (#37816872)
The premise of the sentence you cited is that it is necessary to call application code (constructors) to maintain security/integrity.

What I am saying is that it is NOT necessary to implement secure serialisation and deserialisation because you CAN (and should?) implement it at a different layer and transparently to the application code.

Re:Fury: 170x faster than JDK, blazing fast serialization by... by pron on Monday October 09, 2023 @07:54AM (#37819454)
It is necessary to call application code to maintain integrity (i.e. the guarantee of global program invariants), if you want to design classes for serialization that is agnostic to serialized format and that accounts for cases where not both sides of the communication are trusted. If program objects can be constructed from bits that arrive from external input that might not be trusted, some code needs to run to ensure that the objects maintain their invariants. Of course, you could say that objects cannot maintain any of their own invariants (that is the approach taken by Zig, where, unlike in Java, it is impossible to explicitly define, at the language level, an object that represents only prime integers), but that requires a very different language design, one that has not yet been proven to scale well (and one that isn't taken by Java specifically).
Re:Fury: 170x faster than JDK, blazing fast serialization by... by mkleczek on Monday October 09, 2023 @10:32AM (#37820840)
> if you want to design classes for serialization that is agnostic to serialized format

You mean XML/JSON/binary etc? This is impossible :) - the only thing that comes close is ASN.1.

But serialisation can be easy: just don't do anything and let runtime handle that. Any compacting GC can be seen as serialiser/deserialiser (it does move object graph from one place to another) - and it does not need to run any application code to perform its task. Criu and any other live program ("object") migration methods are similar.

> and that accounts for cases where not both sides of the communication are trusted

I don't believe Java serialisation will ever be capable of handling deserialisation of untrusted input.

Re:Fury: 170x faster than JDK, blazing fast serialization by... by LispSporks22 on Sunday October 08, 2023 @11:50AM (#37811545)
There's also a chapter on JDK serialized in Bloch's "Effective Java" worth a read:

    Item 85: Prefer alternatives to Java serialization
    Item 86: Implement Serializable with great caution
    Item 87: Consider using a custom serialized form
    Item 88: Write readObject methods defensively
    Item 89: For instance control, prefer enum types to readResolve
    Item 90: Consider serialization proxies instead of serialized instances
Re:Fury: 170x faster than JDK, blazing fast serialization by... by chaokunyang on Sunday October 08, 2023 @12:07PM (#37811689)
Those pattern are all supported in fury. And it seems fury are the only framework which implement the jdk `writeObject/readObject/writeReplace/readResolve/readObjectNoData` methods except jdk iteself. Other java serialization will jsut ignore those methods, and get incorect results. But today I'll suggest to avoid to use JDK `riteObject/readObject/`. Since to be compatible with JDK serialization API behaviour, it will introduce performance and space overhead. We can register custom Serializer by fury.registerSerializer(xxx.class, XXXSerializer.class).

`writeReplace/readResolve` are an useful pattern, and can be used when needed.