Fury is a blazing fast multi-language serialization framework powered by jit, vectorization and zero-copy
Project description
Fury is a blazing-fast multi-language serialization framework powered by jit(just-in-time compilation) and zero-copy, providing up to 170x performance and ultimate ease of use.
Features
- Multiple languages: Java/Python/C++/Golang/JavaScript/Rust/Scala/TypeScript.
- Zero-copy: Cross-language out-of-band serialization inspired by pickle5 and off-heap read/write.
- High performance: A highly-extensible JIT framework to generate serializer code at runtime in an async multi-thread way to speed serialization, providing 20-170x speed up by:
- reduce memory access by inlining variables in generated code.
- reduce virtual method invocation by inline call in generated code.
- reduce conditional branching.
- reduce hash lookup.
- Multiple binary protocols: Object graph, row format, and so on.
In addition to cross-language serialization, Fury also features at:
- Drop-in replace Java serialization frameworks such as JDK/Kryo/Hessian without modifying any code, but 100x faster. It can greatly improve the efficiency of high-performance RPC calls, data transfer, and object persistence.
- 100% compatible with JDK serialization: supporting JDK
writeObject/readObject/writeReplace/readResolve/readObjectNoData/Externalizable
serialization API. - Supports Java 8~21, Java 17+
record
is supported too. - Supports shared and circular reference object serialization for golang.
- Supports scala serialization
- Supports automatic object serialization for golang.
Protocols
Different scenarios have different serialization requirements. Fury designed and implemented multiple binary protocols for those requirements:
- Cross-language object graph protocol:
- Cross-language serialize any object automatically, no need for IDL definition, schema compilation and object to/from protocol conversion.
- Support shared reference and circular reference, no duplicate data or recursion error.
- Support object polymorphism.
- Native java/python object graph protocol: Highly-optimized based on type system of the language.
- Row format protocol: A cache-friendly binary random access format, supports skipping serialization and partial serialization, and can convert to column-format automatically.
New protocols can be easily added based on fury existing buffer, encoding, meta, codegen and other capabilities. All of those share the same codebase, and the optimization for one protocol can be reused by another protocol.
Benchmarks
Different serialization frameworks are suitable for different scenarios, and benchmark results here are for reference only.
If you need to benchmark for your specific scenario, make sure all serialization frameworks are appropriately configured for that scenario.
Dynamic serialization frameworks support polymorphism and references, but they often come with a higher cost compared to static serialization frameworks, unless they utilize JIT techniques like Fury does. Because Fury generates code at runtime, it is recommended to warm up the system before collecting benchmark statistics.
Java Serialization
Title containing "compatible" represent schema compatible mode: support type forward/backward compatibility.
Title without "compatible" represent schema consistent mode: class schema must be the same between serialization and deserialization.
Struct
is a class with 100 primitive fields, MediaContent
is a class from jvm-serializers, Sample
is a class from kryo benchmark.
See benchmarks for more benchmarks about type forward/backward compatibility, off-heap support, zero-copy serialization.
Installation
Java
Nightly snapshot:
<repositories>
<repository>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-core</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
<!-- row/arrow format support -->
<!-- <dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-format</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency> -->
Release version:
<dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-core</artifactId>
<version>0.3.1</version>
</dependency>
<!-- row/arrow format support -->
<!-- <dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-format</artifactId>
<version>0.3.1</version>
</dependency> -->
Scala
libraryDependencies += "org.furyio" % "fury-core" % "0.3.1"
Python
# Release version will be provided in the future.
pip install pyfury --pre
JavaScript
npm install @furyjs/fury
Golang
go get github.com/alipay/fury/go/fury
Quickstart
Here we give a quick start about how to use fury, see user guide for more details about java, cross language, and row format.
Fury java object graph serialization
If you don't have cross-language requirements, using this mode will have better performance.
import io.fury.*;
import io.fury.config.*;
import java.util.*;
public class Example {
public static void main(String[] args) {
SomeClass object = new SomeClass();
// Note that Fury instances should be reused between
// multiple serializations of different objects.
{
Fury fury = Fury.builder().withLanguage(Language.JAVA)
// Allow to deserialize objects unknown types, more flexible
// but may be insecure if the classes contains malicious code.
.requireClassRegistration(false)
.build();
// Registering types can reduce class name serialization overhead, but not mandatory.
// If class registration enabled, all custom types must be registered.
fury.register(SomeClass.class);
byte[] bytes = fury.serialize(object);
System.out.println(fury.deserialize(bytes));
}
{
ThreadSafeFury fury = Fury.builder().withLanguage(Language.JAVA)
// Allow to deserialize objects unknown types, more flexible
// but may be insecure if the classes contains malicious code.
.requireClassRegistration(false)
.buildThreadSafeFury();
byte[] bytes = fury.serialize(object);
System.out.println(fury.deserialize(bytes));
}
{
ThreadSafeFury fury = new ThreadLocalFury(classLoader -> {
Fury f = Fury.builder().withLanguage(Language.JAVA)
.withClassLoader(classLoader).build();
f.register(SomeClass.class);
return f;
});
byte[] bytes = fury.serialize(object);
System.out.println(fury.deserialize(bytes));
}
}
}
Cross-language object graph serialization
Java
import io.fury.*;
import io.fury.config.*;
import java.util.*;
public class ReferenceExample {
public static class SomeClass {
SomeClass f1;
Map<String, String> f2;
Map<String, String> f3;
}
public static Object createObject() {
SomeClass obj = new SomeClass();
obj.f1 = obj;
obj.f2 = ofHashMap("k1", "v1", "k2", "v2");
obj.f3 = obj.f2;
return obj;
}
// mvn exec:java -Dexec.mainClass="io.fury.examples.ReferenceExample"
public static void main(String[] args) {
Fury fury = Fury.builder().withLanguage(Language.XLANG)
.withRefTracking(true).build();
fury.register(SomeClass.class, "example.SomeClass");
byte[] bytes = fury.serialize(createObject());
// bytes can be data serialized by other languages.
System.out.println(fury.deserialize(bytes));
}
}
Python
from typing import Dict
import pyfury
class SomeClass:
f1: "SomeClass"
f2: Dict[str, str]
f3: Dict[str, str]
fury = pyfury.Fury(ref_tracking=True)
fury.register_class(SomeClass, "example.SomeClass")
obj = SomeClass()
obj.f2 = {"k1": "v1", "k2": "v2"}
obj.f1, obj.f3 = obj, obj.f2
data = fury.serialize(obj)
# bytes can be data serialized by other languages.
print(fury.deserialize(data))
Golang
package main
import furygo "github.com/alipay/fury/go/fury"
import "fmt"
func main() {
type SomeClass struct {
F1 *SomeClass
F2 map[string]string
F3 map[string]string
}
fury := furygo.NewFury(true)
if err := fury.RegisterTagType("example.SomeClass", SomeClass{}); err != nil {
panic(err)
}
value := &SomeClass{F2: map[string]string{"k1": "v1", "k2": "v2"}}
value.F3 = value.F2
value.F1 = value
bytes, err := fury.Marshal(value)
if err != nil {
}
var newValue interface{}
// bytes can be data serialized by other languages.
if err := fury.Unmarshal(bytes, &newValue); err != nil {
panic(err)
}
fmt.Println(newValue)
}
Row format
Java
public class Bar {
String f1;
List<Long> f2;
}
public class Foo {
int f1;
List<Integer> f2;
Map<String, Integer> f3;
List<Bar> f4;
}
RowEncoder<Foo> encoder = Encoders.bean(Foo.class);
Foo foo = new Foo();
foo.f1 = 10;
foo.f2 = IntStream.range(0, 1000000).boxed().collect(Collectors.toList());
foo.f3 = IntStream.range(0, 1000000).boxed().collect(Collectors.toMap(i -> "k"+i, i->i));
List<Bar> bars = new ArrayList<>(1000000);
for (int i = 0; i < 1000000; i++) {
Bar bar = new Bar();
bar.f1 = "s"+i;
bar.f2 = LongStream.range(0, 10).boxed().collect(Collectors.toList());
bars.add(bar);
}
foo.f4 = bars;
// Can be zero-copy read by python
BinaryRow binaryRow = encoder.toRow(foo);
// can be data from python
Foo newFoo = encoder.fromRow(binaryRow);
// zero-copy read List<Integer> f2
BinaryArray binaryArray2 = binaryRow.getArray(1);
// zero-copy read List<Bar> f4
BinaryArray binaryArray4 = binaryRow.getArray(3);
// zero-copy read 11th element of `readList<Bar> f4`
BinaryRow barStruct = binaryArray4.getStruct(10);
// zero-copy read 6th of f2 of 11th element of `readList<Bar> f4`
barStruct.getArray(1).getLong(5);
RowEncoder<Bar> barEncoder = Encoders.bean(Bar.class);
// deserialize part of data.
Bar newBar = barEncoder.fromRow(barStruct);
Bar newBar2 = barEncoder.fromRow(binaryArray4.getStruct(20));
Python
@dataclass
class Bar:
f1: str
f2: List[pa.int64]
@dataclass
class Foo:
f1: pa.int32
f2: List[pa.int32]
f3: Dict[str, pa.int32]
f4: List[Bar]
encoder = pyfury.encoder(Foo)
foo = Foo(f1=10, f2=list(range(1000_000)),
f3={f"k{i}": i for i in range(1000_000)},
f4=[Bar(f1=f"s{i}", f2=list(range(10))) for i in range(1000_000)])
binary: bytes = encoder.to_row(foo).to_bytes()
foo_row = pyfury.RowData(encoder.schema, binary)
print(foo_row.f2[100000], foo_row.f4[100000].f1, foo_row.f4[200000].f2[5])
Compatibility
Schema Compatibility
Fury java object graph serialization support class schema forward/backward compatibility. The serialization peer and deserialization peer can add/delete fields independently.
We plan to add support cross-language serialization after meta compression is finished.
Binary Compatibility
We are still improving our protocols, binary compatibility is not ensured between fury major releases for now.
it's ensured between minor versions only. Please
versioning
your data by fury major version if you will upgrade fury in the future, see how to upgrade fury for further details.
Binary compatibility will be ensured when fury 1.0 is released.
Security
Static serialization is secure. But dynamic serialization such as fury java/python native serialization supports deserializing unregistered types, which provides more dynamics and flexibility, but also introduce security risks.
For example, the deserialization may invoke init
constructor or equals
/hashCode
method, if the method body contains malicious code, the system will be at risk.
Fury provides a class registration option that is enabled by default for such protocols, allowing only deserialization of trusted registered types or built-in types. Do not disable class registration unless you can ensure your environment is secure.
If this option is disabled, you are responsible for serialization security. You can configure io.fury.resolver.ClassChecker
by
ClassResolver#setClassChecker
to control which classes are allowed for serialization.
How to Build
Please read the BUILD guide for instructions on how to build.
How to Contribute
Please read the CONTRIBUTING guide for instructions on how to contribute.
For ecosystem projects, please see https://github.com/fury-project
Getting involved
Platform | Purpose | Estimated Response Time |
---|---|---|
GitHub Issues | For reporting bugs and filing feature requests. | < 1 days |
Slack | For collaborating with other Fury users and latest announcements about Fury. | < 2 days |
StackOverflow | For asking questions about how to use Fury. | < 2 days |
Zhihu Twitter Youtube | Follow us for latest announcements about Fury. | < 2 days |
WeChat Official Account(微信公众号) / Dingding Group(钉钉群) | < 2 days |
License
Licensed under the Apache License, Version 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pyfury-0.3.1-cp312-cp312-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05016665f361c4db121480233ec92006b2b56b4455f75427edae5dc3f23ac914 |
|
MD5 | 6d44f6d12373aa696588d85100c21ac6 |
|
BLAKE2b-256 | d6e23d8fd3fa230f2828c5043fdc00acb4b47bb597e8becd5833dc6ae7b346f4 |
Hashes for pyfury-0.3.1-cp312-cp312-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cddef28a843e7645370f916412e1ffa60513563e217e4d837bf1644b2d160044 |
|
MD5 | 5a73945619e6a6f2418541df71c5797b |
|
BLAKE2b-256 | cb17c90cb426226814295659cc3e15773cb2711be00c8666dcd7d8c2a8db0a03 |
Hashes for pyfury-0.3.1-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e854d616a2b71d25c55f7a8b026934266ac73d07c858ee89695238be85edbd0e |
|
MD5 | 460a5f2bc609a18e9475d353f52a572c |
|
BLAKE2b-256 | f30b9a44f5956723a18a57e41f8648bf8bb9cdad695f4927c7ff8ec8309450a6 |
Hashes for pyfury-0.3.1-cp311-cp311-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aa89e1b080eb3649ce46d523c60d96205f52c86ed23c201cb4f1ef5dea53b68 |
|
MD5 | d6fbbedd726dd6e2ac946b49ede0b037 |
|
BLAKE2b-256 | 8c2debbbd478ad8224b6b638bc0458a550834e78035f972e9ad62f31da7fccb3 |
Hashes for pyfury-0.3.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c19b9e64fec1395e0c6389485f19329fd80dcf888821c2cc7918b3bfe3e18b33 |
|
MD5 | 1b3c8e2d610d9893051381255576b171 |
|
BLAKE2b-256 | b9427ae27ff29c40b7f5677bf42ca5d7632ff3dd4443b5236c681af48b69dfdc |
Hashes for pyfury-0.3.1-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24c7f3fb64dd85c2858064d8e3279c6e2dd2f1b5d5a4b773dadf778aefa78b91 |
|
MD5 | c76ae4cfec65390f4c0a0b643f2f6265 |
|
BLAKE2b-256 | 4437a8fdd43a3810496ec80fd7b624ef1a330c568f6607b38cb109fe40a77d72 |
Hashes for pyfury-0.3.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4043a8b43f3b99be37251297dc574601ca88004e5585c511a830b25075e3826 |
|
MD5 | 456a5767427cd08c9611d60e963505f0 |
|
BLAKE2b-256 | 19a0f0f74fd8519997c9953bcf75f6faabfe34a019ae0c5cd17453c7b36bd4ec |
Hashes for pyfury-0.3.1-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42a8c5404e0feb862d70b6bda02c6040e73cf5b5bee07c308445560daf16db8b |
|
MD5 | 1f60d030372642cd03e134f5593f541b |
|
BLAKE2b-256 | 85c1e826c5733091d55a0e3b7f2616dcf80afbbf3b142a4c4aa0966f5c610824 |
Hashes for pyfury-0.3.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b2a41ecb0587f88bbf9a83612343fc85a88b8d213a7b5ac9ca2d437eb7de8e7 |
|
MD5 | 1a994d7a215bf11d724bbf0a91df74e0 |
|
BLAKE2b-256 | 58a104e6b70f1b99d84ecb9862945af5132aca78fb049472f7a101ca3dfabc3c |
Hashes for pyfury-0.3.1-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 639c68a544e159ece335f1f2240ff1fd64dd06be27894c52b3b620a0864e829b |
|
MD5 | c2b8ff416b78fde96c7dea06a440447d |
|
BLAKE2b-256 | e0f8269a90d541756f3bb722b3f1842b9797d45e0a60ad420e9f1d0250fb5847 |
Hashes for pyfury-0.3.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7457085009100b1be90b57d594c4fcb8bddf4720b812734affee5676b69698c8 |
|
MD5 | 287fc30a4f82e425c7d3c52f13c754e8 |
|
BLAKE2b-256 | 2fbbe04b8c80bd7eb272ae9acb9f2675003c6c83b9cbe02dfa4853db34b25faa |
Hashes for pyfury-0.3.1-cp37-cp37m-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cc73ea420a142dcf7902488d07d4defc17399f2b1136693598107af71c33c5e |
|
MD5 | 343fe0e962c4b22e827e4f0576dc73bb |
|
BLAKE2b-256 | dea47d64402c56ed9c679c68c6e7d8f14018c7572a4279b5968c838a62a2cb86 |