跳到主要内容

Fory v0.16.0 发布

· 阅读需 15 分钟
杨朝坤

Apache Fory 团队很高兴宣布 0.16.0 版本正式发布。这是一个重要版本,包含来自 17 位贡献者的 91 个 PR。请访问 Install 页面 获取各平台安装方式。

发布亮点

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# 基准测试

以下是代表性数据结构上的耗时结果(ns/op,越低越好),用于比较 Fory、Protobuf 与 Msgpack。

Data TypeOperationForyProtobufMsgpack
StructSerialize39.2121.566.0
StructDeserialize58.3180.1102.6
SampleSerialize269.2562.6339.6
SampleDeserialize175.61084.9531.8
MediaContentSerialize306.3434.7351.5
MediaContentDeserialize379.4718.8676.9
StructListSerialize136.1468.5266.9
StructListDeserialize221.1687.0488.5
SampleListSerialize1198.92811.91635.7
SampleListDeserialize791.55174.52629.2
MediaContentListSerialize1393.92199.41710.9
MediaContentListDeserialize1719.53373.13401.2

序列化数据大小(bytes):

Data TypeForyProtobufMsgpack
Struct586155
Sample446460562
MediaContent365307479
StructList184315284
SampleList198023152819
MediaContentList153515502404

详细基准数据请参见: https://fory.apache.org/docs/benchmarks/csharp/

Swift Serialization:首次发布

Apache Fory 0.16.0 也正式带来了 Swift serialization 的首次发布。Swift 实现重点关注 idiomatic API 设计、基于 macro 的模型序列化、跨语言兼容能力,以及对象图工作负载的支持。

关键能力:

  • 面向 Swift value/reference types 的高性能序列化
  • 使用 @ForyObject macro 实现零样板代码的模型序列化
  • 支持与 Java、Python、C++、Go、Rust 和 JavaScript 的跨语言协议兼容
  • 提供跨版本 Schema 演进所需的兼容模式
  • 支持 AnyAnyObjectany SerializerAnyHashable 等动态值类型
  • 支持共享引用和循环引用图中的引用跟踪,并可处理 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 基准测试

以下是代表性数据结构上的吞吐结果(ops/sec,越高越好),用于比较 Fory、Protobuf 与 Msgpack。

Data TypeOperationForyProtobufMsgpackFastest
StructSerialize9,727,9506,572,406141,248fory (1.48x)
StructDeserialize11,889,5708,584,51099,792fory (1.39x)
SampleSerialize3,496,3051,281,98317,188fory (2.73x)
SampleDeserialize1,045,018765,70612,767fory (1.36x)
MediaContentSerialize1,425,354678,54229,048fory (2.10x)
MediaContentDeserialize614,447478,29812,711fory (1.28x)
StructListSerialize3,307,9621,028,21024,781fory (3.22x)
StructListDeserialize2,788,200708,5968,160fory (3.93x)
SampleListSerialize715,734205,3803,361fory (3.48x)
SampleListDeserialize199,317133,4251,498fory (1.49x)
MediaContentListSerialize364,097103,7215,538fory (3.51x)
MediaContentListDeserialize103,42186,3311,529fory (1.20x)

序列化数据大小(bytes):

Data TypeForyProtobufMsgpack
MediaContent365301524
MediaContentList153515202639
Sample446375737
SampleList198018903698
Struct586165
StructList184315338

详细基准数据请参见: https://fory.apache.org/docs/benchmarks/swift/

功能特性

Bug 修复

其他改进

新贡献者

完整更新日志https://github.com/apache/fory/compare/v0.15.0...v0.16.0