Skip to main content
Version: dev

Configuration

This page covers ForyConfig and recommended runtime presets.

ForyConfig

Fory is configured with:

public struct ForyConfig {
public var xlang: Bool
public var trackRef: Bool
public var compatible: Bool
}

Default configuration:

let fory = Fory() // xlang=true, trackRef=false, compatible=false

Threading

Fory is single-threaded and optimized to reuse one read/write context pair on the calling thread. Reuse one instance per thread and do not use the same instance concurrently.

Options

xlang

Controls cross-language protocol mode.

  • true: Use xlang wire format (default)
  • false: Use Swift-native mode
let fory = Fory(xlang: true)

trackRef

Enables shared/circular reference tracking for reference-trackable types.

  • false: No reference table (smaller/faster for acyclic or value-only graphs)
  • true: Preserve object identity for class/reference graphs
let fory = Fory(xlang: true, trackRef: true)

compatible

Enables compatible schema mode for evolution across versions.

  • false: Schema-consistent mode (stricter, lower metadata overhead)
  • true: Compatible mode (supports add/remove/reorder fields)
let fory = Fory(xlang: true, trackRef: false, compatible: true)

Local, strict schema

let fory = Fory(xlang: false, trackRef: false, compatible: false)

Cross-language service payloads

let fory = Fory(xlang: true, trackRef: false, compatible: true)

Graph/object identity workloads

let fory = Fory(xlang: true, trackRef: true, compatible: true)