Apache Fory 团队很高兴宣布 0.16.0 版本正式发布。这是一个重要版本,包含来自 17 位贡献者的 144 个 PR。请访问 Install 页面 获取各平台安装方式。
发布亮点
- feat(c#): 新增 c# serialization 实现,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3383
- feat(c#): 为 compiler 增加 csharp target 与 idl integration tests,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3406
- feat(swift): 为 Swift 语言实现 fory serialization,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3359
- feat(swift): 新增 fory swift schema idl 代码生成,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3433
- feat(JavaScript): 支持 EXT、NAMED_EXT,作者 @theweipeng, 见 https://github.com/apache/fory/pull/3312
- feat(JavaScript): 对齐 xlang 协议,作者 @theweipeng,见 https://github.com/apache/fory/pull/3316
- refactor(python): 统一 python xlang 与 native mode 的 read/write API,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3348
- feat(c++/python): 为 c++ 和 python 增加 stream deserialization 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3307
- feat(python): 新增高性能 cython struct serializer,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3443
- refactor(java): 统一 serializer write/read API 并移除 xwrite/xread,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3400
C# Serialization:首次发布
Apache Fory 0.16.0 是首个正式提供 C# serialization 支持的版本。C# 运行时面向现代 .NET 工作负载设计,并带来了与其他 Fory 运行时一致的对象图、跨语言和 Schema 演进能力。
关键能力:
- 面向 .NET 8+ 的高性能二进制序列化,并通过
[ForyObject]类型提供基于 source generator 的 serializer - 支持与 Java、Python、C++、Go、Rust 和 JavaScript 的跨语言模式
- 可选的引用跟踪,用于处理共享引用和循环引用对象图
- 用于 Schema 演进的兼容模式
- 支持动态对象载荷、自定义 serializer,以及 namespace/name 注册 API
- 为并发服务工作负载提供
ThreadSafeFory包装器 - 在 Fory IDL/compiler 工作流中提供 C# target 支持
快速开始
using Apache.Fory;
[ForyObject]
public sealed class User
{
public long Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? Email { get; set; }
}
Fory fory = Fory.Builder()
.Xlang(true)
.Compatible(true)
.Build();
fory.Register<User>(1);
byte[] payload = fory.Serialize(new User
{
Id = 1,
Name = "Alice",
Email = "alice@example.com",
});
User decoded = fory.Deserialize<User>(payload);
- C# 指南: https://fory.apache.org/docs/guide/csharp/
- Compiler 文档: https://fory.apache.org/docs/compiler/
C# 基准测试
以下是代表性数据结构上的耗时结果(ns/op,越低越好),用于比较 Fory、Protobuf 与 Msgpack。
| Data Type | Operation | Fory | Protobuf | Msgpack |
|---|---|---|---|---|
| Struct | Serialize | 39.2 | 121.5 | 66.0 |
| Struct | Deserialize | 58.3 | 180.1 | 102.6 |
| Sample | Serialize | 269.2 | 562.6 | 339.6 |
| Sample | Deserialize | 175.6 | 1084.9 | 531.8 |
| MediaContent | Serialize | 306.3 | 434.7 | 351.5 |
| MediaContent | Deserialize | 379.4 | 718.8 | 676.9 |
| StructList | Serialize | 136.1 | 468.5 | 266.9 |
| StructList | Deserialize | 221.1 | 687.0 | 488.5 |
| SampleList | Serialize | 1198.9 | 2811.9 | 1635.7 |
| SampleList | Deserialize | 791.5 | 5174.5 | 2629.2 |
| MediaContentList | Serialize | 1393.9 | 2199.4 | 1710.9 |
| MediaContentList | Deserialize | 1719.5 | 3373.1 | 3401.2 |
序列化数据大小(bytes):
| Data Type | Fory | Protobuf | Msgpack |
|---|---|---|---|
| Struct | 58 | 61 | 55 |
| Sample | 446 | 460 | 562 |
| MediaContent | 365 | 307 | 479 |
| StructList | 184 | 315 | 284 |
| SampleList | 1980 | 2315 | 2819 |
| MediaContentList | 1535 | 1550 | 2404 |
详细基准数据请参见: https://fory.apache.org/docs/benchmarks/csharp/
Swift Serialization:首次发布
Apache Fory 0.16.0 也正式带来了 Swift serialization 的首次发布。Swift 实现重点关注 idiomatic API 设计、基于 macro 的模型序列化、跨语言兼容能力,以及对象图工作负载的支持。
关键能力:
- 面向 Swift value/reference types 的高性能序列化
- 使用
@ForyObjectmacro 实现零样板代码的模型序列化 - 支持与 Java、Python、C++、Go、Rust 和 JavaScript 的跨语言协议兼容
- 提供跨版本 Schema 演进所需的兼容模式
- 支持
Any、AnyObject、any Serializer和AnyHashable等动态值类型 - 支持共享引用和循环引用图中的引用跟踪,并可处理 class 上的弱引用
- 在 Fory IDL/compiler 工作流中提供 Swift target 支持
快速开始
import Fory
@ForyObject
struct User: Equatable {
var name: String = ""
var age: Int32 = 0
}
let fory = Fory(xlang: true, trackRef: false, compatible: true)
fory.register(User.self, id: 1)
let input = User(name: "Alice", age: 30)
let data = try fory.serialize(input)
let output: User = try fory.deserialize(data)
- Swift 指南: https://fory.apache.org/docs/guide/swift/
- Compiler 文档: https://fory.apache.org/docs/compiler/
Swift 基准测试
以下是代表性数据结构上的吞吐结果(ops/sec,越高越好),用于比较 Fory、Protobuf 与 Msgpack。
| Data Type | Operation | Fory | Protobuf | Msgpack | Fastest |
|---|---|---|---|---|---|
| Struct | Serialize | 9,727,950 | 6,572,406 | 141,248 | fory (1.48x) |
| Struct | Deserialize | 11,889,570 | 8,584,510 | 99,792 | fory (1.39x) |
| Sample | Serialize | 3,496,305 | 1,281,983 | 17,188 | fory (2.73x) |
| Sample | Deserialize | 1,045,018 | 765,706 | 12,767 | fory (1.36x) |
| MediaContent | Serialize | 1,425,354 | 678,542 | 29,048 | fory (2.10x) |
| MediaContent | Deserialize | 614,447 | 478,298 | 12,711 | fory (1.28x) |
| StructList | Serialize | 3,307,962 | 1,028,210 | 24,781 | fory (3.22x) |
| StructList | Deserialize | 2,788,200 | 708,596 | 8,160 | fory (3.93x) |
| SampleList | Serialize | 715,734 | 205,380 | 3,361 | fory (3.48x) |
| SampleList | Deserialize | 199,317 | 133,425 | 1,498 | fory (1.49x) |
| MediaContentList | Serialize | 364,097 | 103,721 | 5,538 | fory (3.51x) |
| MediaContentList | Deserialize | 103,421 | 86,331 | 1,529 | fory (1.20x) |
序列化数据大小(bytes):
| Data Type | Fory | Protobuf | Msgpack |
|---|---|---|---|
| MediaContent | 365 | 301 | 524 |
| MediaContentList | 1535 | 1520 | 2639 |
| Sample | 446 | 375 | 737 |
| SampleList | 1980 | 1890 | 3698 |
| Struct | 58 | 61 | 65 |
| StructList | 184 | 315 | 338 |
详细基准数据请参见: https://fory.apache.org/docs/benchmarks/swift/
功能特性
- feat(grpc): 更新 lexer/parser,支持为 idl compiler 定义 service 和 rpc,作者 @ayush00git,见 https://github.com/apache/fory/pull/3308
- feat(JavaScript): 支持 EXT、NAMED_EXT,作者 @theweipeng,见 https://github.com/apache/fory/pull/3312
- feat(go): 为 uint64slice 补充缺失的 type resolver,作者 @BrianLii,见 https://github.com/apache/fory/pull/3311
- feat(JavaScript): 支持 ForyField,作者 @theweipeng,见 https://github.com/apache/fory/pull/3314
- feat(JavaScript): 对齐 xlang 协议,作者 @theweipeng,见 https://github.com/apache/fory/pull/3316
- feat(javascript): 增加 float16 支持,作者 @ayush00git,见 https://github.com/apache/fory/pull/3253
- feat(JavaScript): 对齐测试用例,作者 @theweipeng,见 https://github.com/apache/fory/pull/3319
- feat(go): 更新 createSerializer 中的 float16 array/slice 逻辑,作者 @BrianLii,见 https://github.com/apache/fory/pull/3318
- feat(JavaScript): 对齐测试用例,作者 @theweipeng,见 https://github.com/apache/fory/pull/3320
- feat(JavaScript): 对齐测试用例,作者 @theweipeng,见 https://github.com/apache/fory/pull/3321
- feat(dart): 对齐 dart xlang serialization,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3322
- feat(go): 提升 int slice primitive serializer 的测试覆盖率,作者 @BrianLii,见 https://github.com/apache/fory/pull/3313
- refactor(dart): 重整 runtime API 并统一 codegen 命名,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3323
- feat(JavaScript): 对齐 xlang 协议,作者 @theweipeng,见 https://github.com/apache/fory/pull/3326
- feat(JavaScript): 修复
test_polymorphic_map,作者 @theweipeng,见 https://github.com/apache/fory/pull/3327 - feat(dart): 对齐 dart 与 xlang serialization spec,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3325
- feat(go): 增加 bfloat16 支持,作者 @BrianLii,见 https://github.com/apache/fory/pull/3310
- feat(javascript): 增加 bfloat16 与 bfloat16_array 支持,作者 @miantalha45,见 https://github.com/apache/fory/pull/3328
- feat(JavaScript): 修复测试用例,作者 @theweipeng,见 https://github.com/apache/fory/pull/3334
- refactor(dart): 按 Type 注册 xlang 类型,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3332
- feat(javascript): 统一 buffer read/write API 与 Java 命名风格,作者 @miantalha45,见 https://github.com/apache/fory/pull/3346
- refactor(python): 统一 python xlang 与 native mode 的 read/write API,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3348
- feat(dart): 为 dart 增加 float16,作者 @ayush00git,见 https://github.com/apache/fory/pull/3336
- feat(swift): 为 Swift 语言实现 fory serialization,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3359
- feat(compiler): 为 fory compiler 增加 gRPC flags,作者 @ayush00git,见 https://github.com/apache/fory/pull/3361
- feat(swift): 为 fory swift 实现 Schema 演进兼容模式,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3363
- feat(swift): 为多态场景增加 dynamic any serializer,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3368
- feat(swift): 为 swift 增加 enum/time serialization 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3371
- feat(c++): 增加 msgpack cpp benchmark,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3365
- feat(swift): 增加直接的 Fory initializer,并更新 Swift 文档,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3373
- feat: 为 Rust 运行时增加 IEEE 754 float16(binary16)支持,作者 @AshharAhmadKhan,见 https://github.com/apache/fory/pull/3252
- feat(c#): 新增 c# serialization 实现,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3383
- perf(csharp): 增加 csharp benchmark 并优化热点序列化路径,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3396
- refactor(benchmarks): 重命名 benchmark 目录并更新链接,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3398
- refactor(java): 统一 serializer write/read API 并移除 xwrite/xread,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3400
- perf(swift): 增加 fory swift serialization benchmark 并优化性能,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3395
- refactor(c#): 重构 serializer 接口以缩小 API surface,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3403
- feat(compiler): 为 compiler 增加 csharp target 与 idl integration tests,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3406
- feat(swift): 加固 decode 路径并补齐缺失的 wire type 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3427
- feat(c#): 增加 max depth 与代码 lint 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3428
- feat(c++/python): 为 c++ 和 python 增加 stream deserialization 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3307
- feat(swift): 新增 fory swift schema idl 代码生成,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3433
- feat(dart): 增加可配置的反序列化大小护栏,作者 @yash-agarwa-l,见 https://github.com/apache/fory/pull/3434
- refactor(dart): 将所有 runtime 异常合并到单个
fory_exception.dart中,作者 @yash-agarwa-l,见 https://github.com/apache/fory/pull/3436 - perf(python): 优化 pyfory collection serialization 性能,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3441
- feat(python): 新增高性能 cython struct serializer,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3443
- perf(python): 增加 python benchmark suite,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3448
- feat(python/cpp): 为 python 和 c++ 增加 stream serialization 支持,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3449
- feat(python/c++): 在 struct 反序列化后收缩 stream buffer,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3453
- perf(c#): 增加 csharp benchmark 结果,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3451
- refactor: 清理 java serialize API,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3454
- feat(rust): 禁止在 resolver snapshot 初始化后继续进行类型注册,作者 @Geethapranay1,见 https://github.com/apache/fory/pull/3435
- perf(ci): 为 Rust CI job 增加 Cargo 缓存,作者 @moon3482,见 https://github.com/apache/fory/pull/3431
- feat(python): 增加可配置的大小护栏,作者 @eyad-hazem-elmorsy,见 https://github.com/apache/fory/pull/3429
- feat(go): 增加通过 io streams 进行 go 反序列化的支持,作者 @ayush00git,见 https://github.com/apache/fory/pull/3374
- perf(go): 移除
//go:inline指令,并将冷路径标记为//go:noinline,作者 @ayush00git,见 https://github.com/apache/fory/pull/3456 - feat(c++): 增加可配置的反 序列化大小护栏,作者 @shivendra-dev54,见 https://github.com/apache/fory/pull/3455
- perf(swift): 优化 swift 性能,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3457
- feat(swift): 让 fory swift 可以作为依赖使用,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3462
- perf: 增加 fory performance optimization skill,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3463
- feat(xlang): 支持按类型覆盖演进策略,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3465
- feat(javascript): 为 deserialize 与 serialize 增加深度限制,作者 @miantalha45,见 https://github.com/apache/fory/pull/3382
Bug 修复
- fix(java): 修复带有覆盖方法的枚举在 EnumSetSerializer 中的问题,作者 @NotLebedev,见 https://github.com/apache/fory/pull/3315
- fix(java): 修复嵌套 HashMap 子类的反序列化问题,作者 @mandrean,见 https://github.com/apache/fory/pull/3342
- fix(java): 修复 SortedSet/SortedMapSerializer 在无 Comparator 构造函数的 TreeSet/TreeMap 子类上的支持问题,作者 @mandrean,见 https://github.com/apache/fory/pull/3344
- fix(c++): 修复 buffer 读写越界检查,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3418
- fix: 避免
supportCodegenForJavaSerialization中出现NoClassDefFoundError,作者 @siy,见 https://github.com/apache/fory/pull/3424 - fix(docs): 更新 compiler guide,作者 @ayush00git,见 https://github.com/apache/fory/pull/3420
- fix(python): 返回带 UTC 时区的 datetime,而不是 naive datetime,作者 @yuta4895,见 https://github.com/apache/fory/pull/3439
- fix(docs): 调整 sidebar 位置并修正拼写错误,作者 @ayush00git,见 https://github.com/apache/fory/pull/3450
- fix(python): 支持 tuple dataclass 字段和对象实例,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3468
- fix(python): 修复 python wheel 构建,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3469
- fix(java): 避免在无效输入上出现 deflater meta 解压挂起,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3472
其他改进
- docs: 更新 guide 与 compiler 文档,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3298
- docs: 修复文档断链并增加 fory-site check CI,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3299
- docs(java): 更新 java benchmark 图片,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3304
- docs(c++): 更新 readme 与 benchmark 文档,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3305
- docs: 修复错误文档内容,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3309
- chore: 将发布版本提升到 0.15.0,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3317
- chore(deps): 将
/benchmarks/java_benchmark中的org.apache.avro:avro从 1.11.4 升级到 1.11.5,作者 @dependabot[bot],见 https://github.com/apache/fory/pull/3338 - chore(python): 为开发环境定义依赖,作者 @yuta4895,见 https://github.com/apache/fory/pull/3360
- docs(java): 更新 java benchmark 图表,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3366
- docs(swift): 优化 swift API 与文档,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3372
- chore: 将 MessagePack 从 2.5.172 升级到 2.5.187,作者 @dependabot[bot],见 https://github.com/apache/fory/pull/3401
- docs(csharp): 增加 csharp guide 并更新 README,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3404
- docs: 调整 guide 文档 sidebar,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3407
- chore(python): 处理重复字段名,作者 @eyad-hazem-elmorsy,见 https://github.com/apache/fory/pull/3384
- docs: 修复语法错误 “we follows” -> “we follow”,作者 @04cb,见 https://github.com/apache/fory/pull/3442
- chore(c#): 为 c# 发布做准备,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3464
- docs: 增加 AI 贡献策略,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3437
- docs: 简化 PR AI checklist,并重命名 AI policy 文件,作者 @chaokunyang,见 https://github.com/apache/fory/pull/3470
新贡献者
- @BrianLii 在 https://github.com/apache/fory/pull/3311 完成了首次贡献
- @NotLebedev 在 https://github.com/apache/fory/pull/3315 完成了首次贡献
- @miantalha45 在 https://github.com/apache/fory/pull/3328 完成了首次贡献
- @yuta4895 在 https://github.com/apache/fory/pull/3360 完成了首次贡献
- @AshharAhmadKhan 在 https://github.com/apache/fory/pull/3252 完成了首次贡献
- @siy 在 https://github.com/apache/fory/pull/3424 完成了首次贡献
- @yash-agarwa-l 在 https://github.com/apache/fory/pull/3434 完成了首次贡献
- @eyad-hazem-elmorsy 在 https://github.com/apache/fory/pull/3384 完成了首次贡献
- @04cb 在 https://github.com/apache/fory/pull/3442 完成了首次贡献
- @Geethapranay1 在 https://github.com/apache/fory/pull/3435 完成了首次贡献
- @moon3482 在 https://github.com/apache/fory/pull/3431 完成了首次贡献
- @shivendra-dev54 在 https://github.com/apache/fory/pull/3455 完成了首次贡献
完整更新日志: https://github.com/apache/fory/compare/v0.15.0...v0.16.0
