Skip to content

perf(swift): add fory swift serialization benchmark and optimize perf#3395

Merged
chaokunyang merged 10 commits intoapache:mainfrom
chaokunyang:add_swift_benchmark
Feb 24, 2026
Merged

perf(swift): add fory swift serialization benchmark and optimize perf#3395
chaokunyang merged 10 commits intoapache:mainfrom
chaokunyang:add_swift_benchmark

Conversation

@chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Feb 23, 2026

Why?

  • Add a reproducible Swift benchmark suite across fory/protobuf/msgpack and document current performance.
  • Optimize Swift serialization/deserialization hot paths without changing the Fory protocol.

What does this PR do?

  • Adds a new Swift benchmark suite under benchmarks/swift:
    • benchmark harness, datasets, and runners (BenchmarkRunner, main.swift)
    • protobuf schema + generated Swift bindings for parity (bench.proto, bench.pb.swift)
    • one-command run script and markdown/plot report generator (run.sh, benchmark_report.py)
  • Optimizes Swift runtime hot paths in core serialization/deserialization:
    • ByteBuffer varint/buffer paths
    • collection/object serializer paths (CollectionSerializers, Serializer, Fory, Context, RefResolver)
    • macro and type metadata plumbing updates (ForyObjectMacro, TypeMeta, TypeResolver)
  • Avoids an extra UTF-8 byte copy in the string decode path.
  • Refactors type-id naming: ForyTypeId -> TypeId (swift/Sources/TypeId.swift).
  • Includes CI follow-up fixes:
    • style-format benchmarks/swift/benchmark_report.py
    • simplify two large UInt64 varint expressions in ByteBuffer to avoid Swift compiler type-check timeout on macOS CI.

Related issues

#3349
#3355

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

Swift benchmark result (benchmarks/swift/results/REPORT.md)

Key Value
Timestamp 2026-02-24T09:07:22Z
OS Version 15.7.2 (Build 24G325)
Host macbook-pro.local
CPU Cores (Logical) 12
Memory (GB) 48.00
Duration per case (s) 3
Datatype Operation Fory TPS Protobuf TPS Msgpack TPS Fastest
Struct Serialize 6,594,978 6,510,524 143,221 fory (1.01x)
Struct Deserialize 21,546,392 9,413,296 99,321 fory (2.29x)
Sample Serialize 2,830,973 1,292,133 16,805 fory (2.19x)
Sample Deserialize 1,043,252 752,382 12,515 fory (1.39x)
MediaContent Serialize 1,487,110 667,043 28,348 fory (2.23x)
MediaContent Deserialize 895,491 466,411 12,605 fory (1.92x)
StructList Serialize 2,238,338 1,019,259 24,186 fory (2.20x)
StructList Deserialize 2,737,618 803,488 8,600 fory (3.41x)
SampleList Serialize 600,480 195,762 3,314 fory (3.07x)
SampleList Deserialize 170,963 123,110 1,500 fory (1.39x)
MediaContentList Serialize 330,343 103,388 5,472 fory (3.20x)
MediaContentList Deserialize 173,235 86,549 1,499 fory (2.00x)
Datatype Fory Protobuf Msgpack
MediaContent 287 301 524
MediaContentList 1435 1520 2639
Sample 380 375 737
SampleList 1900 1890 3698
Struct 28 61 65
StructList 140 315 338

@chaokunyang chaokunyang merged commit d988a74 into apache:main Feb 24, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants