Apache Fory 团队很高兴宣布 0.15.0 版本正式发布。这是一个重要版本,包含来自 17 位贡献者的 144 个 PR。请访问 Install 页面 获取各平台安装方式。
发布亮点
- feat(go): 新增 golang xlang 序列化实现,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3063
- feat(rust): 添加 tuple struct 支持并改进泛型类型处理,作者 @ariesdevil,见 https://github.com/apache/fory/pull/3087
- refactor(rust): 统一 tuple struct 与 named struct 协议,并改进 schema evolution 兼容性,作者 @ariesdevil,见 https://github.com/apache/fory/pull/3092
- feat(java/python/rust/go/cpp): 对齐 xlang 结构体字段序列化的 nullable 元信息,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3093
- feat(java/python/rust/go/cpp): 对齐 xlang 字段的引用与类型信息,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3107
- feat(cpp): 添加
SharedWeak<T>以支持循环引用,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3109 - feat(xlang): 为 xlang 增加无符号整数支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3111 and https://github.com/apache/fory/pull/3113
- feat(xlang/java): 重构 Java native 序列化类型系统,并为 xlang 引入流式类型信息,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3153
- feat(xlang): 新增 fory schema idl 与 compiler,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3106
- feat(compiler): 添加 flatbuffers idl 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3184
Go Serialization:首次发布
Apache Fory 0.15.0 是首个正式提供 Go serialization 支持的版本。 该实现提供了高性能序列化能力、跨语言兼容性,以及面向生产环境的配置选项。
关键能力:
- 支持与 Java、Python、
cpp、Rust、JavaScript 的 Cross-language mode(fory.WithXlang(true)) - 默认基于 reflection 的 serialization,并提供可选的实验性 AOT code generation 以优化 hot paths
- 支持 shared/circular object graphs 的 reference tracking(
fory.WithTrackRef(true)+fory:"ref"tags) - 提供用于 schema evolution 的 Compatible mode(
fory.WithCompatible(true)),支持字段新增/删除/重排 - 提供 thread-safe wrapper(
github.com/apache/fory/go/fory/threadsafe)以支持并发工作负载
快速开始
package main
import (
"github.com/apache/fory/go/fory"
)
type User struct {
ID int64
Name string
}
func main() {
f := fory.New(
fory.WithXlang(true),
fory.WithCompatible(true),
)
_ = f.RegisterStruct(User{}, 1)
data, _ := f.Serialize(&User{ID: 1, Name: "Alice"})
var out User
_ = f.Deserialize(data, &out)
}
Go 基准测试
以下是代表性数据结构上 的耗时结果(ns/op,越低越好),用于比较 Fory、Protobuf 与 Msgpack。
| Data Type | Operation | Fory | Protobuf | Msgpack |
|---|---|---|---|---|
| Struct | Serialize | 66.0 | 97.8 | 184.9 |
| Struct | Deserialize | 82.7 | 90.9 | 309.6 |
| Structlist | Serialize | 632.8 | 1783.0 | 3340.0 |
| Structlist | Deserialize | 906.4 | 1891.0 | 5709.0 |
| Sample | Serialize | 137.3 | 367.3 | 1492.0 |
| Sample | Deserialize | 263.6 | 422.2 | 2661.0 |
| Samplelist | Serialize | 1962.0 | 7087.0 | 26169.0 |
| Samplelist | Deserialize | 4234.0 | 9321.0 | 53615.0 |
| Mediacontent | Serialize | 268.8 | 471.1 | 773.7 |
| Mediacontent | Deserialize | 426.9 | 553.1 | 1432.0 |
| Mediacontentlist | Serialize | 3736.0 | 9107.0 | 13911.0 |
| Mediacontentlist | Deserialize | 7247.0 | 11435.0 | 27975.0 |
序列化数据大小(bytes):
| Data Type | Fory | Protobuf | Msgpack |
|---|---|---|---|
| Struct | 58 | 61 | 57 |
| Sample | 446 | 375 | 524 |
| MediaContent | 342 | 301 | 400 |
| StructList | 560 | 1260 | 1146 |
| SampleList | 7600 | 7560 | 10486 |
| MediaContentList | 5776 | 6080 | 8006 |
注:结果与硬件和实现版本相关。详细说明请参考 Go benchmark 文档: https://fory.apache.org/docs/benchmarks/go/
Fory Schema IDL 与 Compiler:首次发布
Apache Fory 0.15.0 同时带来了 Fory schema IDL 与 compiler toolchain 的首次发布。你可以一次定义 schema,并为多语言生成 native types 与 registration code。
关键能力:
- Schema-first 开发,支持
enum、message、union - Fory-native 字段语义:
optional(nullability)、ref(shared/circular references)、list、map - 支持 Java、Python、Go、Rust 与
cpp的多语言代码生成 - 支持 Protobuf(
.proto)与 FlatBuffers(.fbs)前端,并转换为 Fory IR/codegen - 提供 idiomatic 的生成 API,并包含
to/from byteshelper
快速开始
pip install fory-compiler
foryc example.fdl --lang java,python,go,rust,cpp --output ./generated
package example;
message Person [id=101] {
string name = 1;
optional string email = 2;
}
