This file provides comprehensive guidance to AI coding agents when working with the Apache Fory codebase.
While working on Fory, please remember:
- Do not reserve any legacy code/docs unless requested clearly.
- Performance First: Performance is the top priority. Never introduce code that reduces performance without explicit justification.
- English Only: Always use English in code, comments, and documentation.
- Meaningful Comments: Only add comments when the code's behavior is difficult to understand or when documenting complex algorithms.
- Focused Testing: Only add tests that verify internal behaviors or fix specific bugs; don't create unnecessary tests unless requested.
- Git-Tracked Files: When reading code, skip all files not tracked by git by default unless generated by yourself.
- Cross-Language Consistency: Maintain consistency across language implementations while respecting language-specific idioms.
- GraalVM support using fory codegen: For GraalVM, use
fory codegento generate the serializer when building a native image. Do not use GraalVM reflect-related configuration unless for JDKproxy. - Xlang Type System: Java
native mode(xlang=false)shares same type systems between type id fromTypes.BOOL~Types.STRINGwithxlang mode(xlang=true), but for other types, javanative modehas different type ids. - Remote git repository:
git@github.com:apache/fory.gitis remote repository, do not use other remote repository when you want to check code undermainbranch,apache/mainis the only target main branch instead oforigin/main - Refresh remote main before compare: before any diff/review/compare against
apache/main, always rungit fetch apache mainfirst so comparisons use the latest remote main. - Contributor git repository: A contributor should fork the
git@github.com:apache/fory.gitrepo, and git push the code changes into their forked repo, then create a pull request from the branch in their forked repo intogit@github.com:apache/fory.git. - Debug Test Errors: always set environment variable
ENABLE_FORY_DEBUG_OUTPUTto1to see debug output.
- Primary references:
README.md,CONTRIBUTING.md,docs/guide/DEVELOPMENT.md, and language guides underdocs/guide/. - Protocol changes: Read and update the relevant specs in
docs/specification/**and align cross-language tests. - Docs publishing: Updates under
docs/guide/anddocs/benchmarks/are synced to https://github.com/apache/fory-site; other website content should be changed in that repo. - Benchmark docs refresh is mandatory: When any benchmark logic/script/config or compared serializer set changes, rerun the relevant benchmarks and refresh corresponding artifacts under
docs/benchmarks/**(report + plots) before finalizing. - Debugging docs: C++ debugging guidance lives in
docs/cpp_debug.md. - Conflicts: If instructions conflict, follow the most specific module docs and call out the conflict in your response.
- All maven commands must be executed within the
javadirectory. - All changes to
javamust pass the code style check and tests. - Fory java needs JDK
17+installed. - Modules target different bytecode levels (fory-core Java 8, fory-format Java 11); avoid using newer APIs in those modules.
- Use '.*' form of import is not allowed.
- If you run temporary tests using
java -cp, you must runmvn -T16 install -DskipTeststo get latest jars for fory java library.
# Clean the build
mvn -T16 clean
# Build
mvn -T16 package
# Install
mvn -T16 install -DskipTests
# Code format check
mvn -T16 spotless:check
# Code format
mvn -T16 spotless:apply
# Code style check
mvn -T16 checkstyle:check
# Run tests
mvn -T16 test
# Run specific tests
mvn -T16 test -Dtest=org.apache.fory.TestClass#testMethod- All dotnet commands must be executed within the
csharpdirectory. - All changes to
csharpmust pass formatting and tests. - Fory C# requires .NET SDK
8.0+and C#12+. - Use
dotnet formatto keep C# code style consistent.
# Restore
dotnet restore Fory.sln
# Build
dotnet build Fory.sln -c Release --no-restore
# Run tests
dotnet test Fory.sln -c Release
# Run specific test
dotnet test tests/Fory.Tests/Fory.Tests.csproj -c Release --filter "FullyQualifiedName~ForyRuntimeTests.DynamicObjectReadDepthExceededThrows"
# Format code
dotnet format Fory.sln
# Format check
dotnet format Fory.sln --verify-no-changesRun C# xlang tests:
cd java
mvn -T16 install -DskipTests
cd fory-core
FORY_CSHARP_JAVA_CI=1 ENABLE_FORY_DEBUG_OUTPUT=1 mvn -T16 test -Dtest=org.apache.fory.xlang.CSharpXlangTest- All commands must be executed within the
cppdirectory. - Fory c++ use c++ 17, you must not use features from higher version of C++.
- Bazel uses bzlmod (
MODULE.bazel); prefer Bazel 8+. - For Bazel C++ tests, detect machine architecture and only add
--config=x86_64onx86_64/amd64; onarm64/aarch64, do not enable this config. - When you updated the code, use
clang-formatto update the code - When invoking a method that returns
Result, always useFORY_TRYunless in a control flow context. - Wrap error checks with
FORY_PREDICT_FALSEfor branch prediction optimization. - Continue on error for trivial errors; only return early for critical errors like buffer overflow.
- private methods should be put last in class def, before private fields.
# Build C++ library
bazel build //cpp/...
# Build Cython extensions (replace X.Y with your Python version, e.g., 3.10)
bazel build //:cp_fory_so --@rules_python//python/config_settings:python_version=X.Y
# Run tests
bazel test $(bazel query //cpp/...)
# Run serialization tests
bazel test $(bazel query //cpp/fory/serialization/...)
# Run specific test
bazel test //cpp/fory/util:buffer_test
# format c++ code
clang-format -i $fileRun C++ xlang tests:
cd java
mvn -T16 install -DskipTests
cd fory-core
FORY_CPP_JAVA_CI=1 ENABLE_FORY_DEBUG_OUTPUT=1 mvn -T16 test -Dtest=org.apache.fory.xlang.CPPXlangTest- All commands must be executed within the
pythondirectory. - All changes to
pythonmust pass the code style check and tests. - When running tests, you can use the
ENABLE_FORY_CYTHON_SERIALIZATIONenvironment variable to enable or disable cython serialization. - When debugging protocol related issues, you should use
ENABLE_FORY_CYTHON_SERIALIZATION=0first to verify the behavior. - Fory python needs cpython
3.8+installed although some modules such asfory-coreusejava8.
# clean build
rm -rf build dist .pytest_cache
bazel clean --expunge
# Code format
ruff format .
ruff check --fix .
# Install
pip install -v -e .
# Build native extension when cython code changed (replace X.Y with your Python version)
bazel build //:cp_fory_so --@rules_python//python/config_settings:python_version=X.Y --config=x86_64 # For x86_64
bazel build //:cp_fory_so --@rules_python//python/config_settings:python_version=X.Y --copt=-fsigned-char # For arm64 and aarch64
# Run tests without cython
ENABLE_FORY_CYTHON_SERIALIZATION=0 pytest -v -s .
# Run tests with cython
ENABLE_FORY_CYTHON_SERIALIZATION=1 pytest -v -s .Run Python xlang tests:
cd java
mvn -T16 install -DskipTests
cd fory-core
# disable fory cython for faster debugging
FORY_PYTHON_JAVA_CI=1 ENABLE_FORY_CYTHON_SERIALIZATION=0 ENABLE_FORY_DEBUG_OUTPUT=1 mvn -T16 test -Dtest=org.apache.fory.xlang.PythonXlangTest
# enable fory cython
FORY_PYTHON_JAVA_CI=1 ENABLE_FORY_CYTHON_SERIALIZATION=1 ENABLE_FORY_DEBUG_OUTPUT=1 mvn -T16 test -Dtest=org.apache.fory.xlang.PythonXlangTest- All commands must be executed within the
go/forydirectory. - All changes to
gomust pass the format check and tests. - Go implementation focuses on reflection-based and codegen-based serialization.
- Set
FORY_PANIC_ON_ERROR=1when debugging test errors to see full callstack. - You must not set
FORY_PANIC_ON_ERROR=1when running all go tests to check whether all tests pass, some tests will check Error content, which will fail if error just panic.
# Format code
go fmt ./...
# Run tests
go test -v ./...
# Run tests with race detection
go test -race -v ./...
# Build
go build
# Generate code (if using go:generate)
go generate ./...Run Go xlang tests:
cd java
mvn -T16 install -DskipTests
cd fory-core
FORY_GO_JAVA_CI=1 ENABLE_FORY_DEBUG_OUTPUT=1 mvn test -Dtest=org.apache.fory.xlang.GoXlangTest- All cargo commands must be executed within the
rustdirectory. - All changes to
rustmust pass the clippy check and tests. - You must set
RUST_BACKTRACE=1 FORY_PANIC_ON_ERROR=1when debugging rust tests to get backtrace. - You must add
-- --nocaptureto cargo test command when debugging tests. - You must not set
FORY_PANIC_ON_ERROR=1when running all rust tests to check whether all tests pass, some tests will check Error content, which will fail if error just panic.
# Check code
cargo check
# Build
cargo build
# Run linter for all services.
cargo clippy --all-targets --all-features -- -D warnings
# Run tests (requires test features)
cargo test --features tests
# run specific test
cargo test -p tests --test $test_file $test_method
# run specific test under subdirectory
cargo test --test mod $dir$::$test_file::$test_method
# debug specific test under subdirectory and get backtrace
RUST_BACKTRACE=1 FORY_PANIC_ON_ERROR=1 ENABLE_FORY_DEBUG_OUTPUT=1 cargo test --test mod $dir$::$test_file::$test_method -- --nocapture
# inspect generated code by fory derive macro
cargo expand --test mod $mod$::$file$ > expanded.rs
# Format code
cargo fmt
# Check formatting
cargo fmt --check
# Build documentation
cargo doc --lib --no-deps --all-features
# Run benchmarks
cd $project_dir/benchmarks/rust
cargo benchRun Rust xlang tests:
cd java
mvn -T16 install -DskipTests
cd fory-core
RUST_BACKTRACE=1 FORY_PANIC_ON_ERROR=1 FORY_RUST_JAVA_CI=1 ENABLE_FORY_DEBUG_OUTPUT=1 mvn test -Dtest=org.apache.fory.xlang.RustXlangTest- All commands must be executed within the
swiftdirectory. - All changes to
swiftmust pass lint and tests. - Swift lint uses
swift/.swiftlint.yml. - Use
ENABLE_FORY_DEBUG_OUTPUT=1when debugging Swift tests.
# Build package
swift build
# Run tests
swift test
# Run tests with debug output
ENABLE_FORY_DEBUG_OUTPUT=1 swift test
# Lint check
swiftlint lint --config .swiftlint.yml
# Auto-fix lint issues where supported
swiftlint --fix --config .swiftlint.ymlRun Swift xlang tests:
cd swift
swift build -c release --disable-automatic-resolution --product ForyXlangTests
cd ../java
mvn -T16 install -DskipTests
cd fory-core
FORY_SWIFT_JAVA_CI=1 ENABLE_FORY_DEBUG_OUTPUT=1 mvn -T16 test -Dtest=org.apache.fory.xlang.SwiftXlangTest- All commands must be executed within the
javascriptdirectory. - Uses npm/yarn for package management.
# Install dependencies
npm install
# Run tests
node ./node_modules/.bin/jest --ci --reporters=default --reporters=jest-junit
# Format code
git ls-files -- '*.ts' | xargs -P 5 node ./node_modules/.bin/eslint- All commands must be executed within the
dartdirectory. - Uses pub for package management.
# First, generate necessary code
dart run build_runner build
# Run all tests
dart test
# Format code
dart analyze
dart fix --dry-run
dart fix --apply- All maven commands must be executed within the
kotlindirectory. - Kotlin implementation provides extra serializers for kotlin types.
- Kotlin implementation is built on fory java, please install the java libraries first by
cd ../java && mvn -T16 install -DskipTests. If no code changes after installed fory java, you can skip the installation step.
# Build
mvn clean package
# Run tests
mvn test- All commands must be executed within the
scaladirectory. - Scala implementation provides extra serializers for Scala types.
- Scala implementation is built on fory java, please install the java libraries first by
cd ../java && mvn -T16 install -DskipTests. If no code changes after installed fory java, you can skip the installation step.
# Build with sbt
sbt compile
# Run tests
sbt test
# Format code
sbt scalafmt- All commands must be executed within the
integration_testsdirectory. - For java related integration tests, please install the java libraries first by
cd ../java && mvn -T16 install -DskipTests. If no code changes after installed fory java, you can skip the installation step. - For mac, graalvm is installed at
/Library/Java/JavaVirtualMachines/graalvm-xxxby default. - For
integration_tests/idl_tests(mandatory prerequisites):- Always run
cd ../java && mvn -T16 install -DskipTestsbefore anyidl_testsrun if there were changes underjava/since the last install. If unsure, run it. - Always run
cd ../python && pip install -v -e .(and rebuild Cython if needed) before anyidl_testsrun if there were changes to Cython-related code underpython/. If unsure, run it.
- Always run
- You are never allowed to manual edit generated code by fory compiler for
IDLfiles, you must invoke fory compiler to regenerate code.
it_dir=$(pwd)
# Run graalvm tests
cd $it_dir/graalvm_tests && mvn -T16 -DskipTests=true -Pnative package && target/main
# Run JDK compatibility tests
cd $it_dir/jdk_compatibility_tests && mvn -T16 test
# Run JPMS tests
cd $it_dir/jpms_tests && mvn -T16 test
# Run Python benchmarks
cd $it_dir/cpython_benchmark && pip install -r requirements.txt && python benchmark.py- Markdown Formatting: When updating markdown documentation, use
prettier --write $fileto format. - API Documentation: When updating important public APIs, update documentation under
docs/. - Protocol Specifications:
docs/specification/**contains Fory protocol specifications. Read these documents carefully before making protocol changes. - User Guides:
docs/guide/**contains user guides for different features and languages. - Repo-wide formatting:
bash ci/format.sh --allruns format/lint across languages.
Apache Fory is an open-source project hosted on GitHub.
The git repository for Apache Fory is https://github.com/apache/fory .
Contributors always fork the repository and create a pull request to propose changes.
The origin points to forked repository instead of the official repository.
-
docs/: Documentation, specifications, and guidesdocs/specification/: Protocol specifications (critical for understanding)docs/guide/: User guides and development guidesdocs/benchmarks/: Performance benchmarks documentation
-
benchmarks/: Benchmark suites and harnesses -
examples/: Usage examples and sample code -
compiler/: Code generation and compiler-related utilities -
Language Implementations:
java/: Java implementation (maven-based, multi-module)csharp/: C# implementation (.NET SDK + source generator)python/: Python implementation (pip/setuptools + bazel)cpp/: C++ implementation (bazel-based)go/: Go implementation (go modules)rust/: Rust implementation (cargo-based)javascript/: JavaScript/TypeScript implementation (npm-based)dart/: Dart implementation (pub-based)kotlin/: Kotlin implementation (maven-based)scala/: Scala implementation (sbt-based)
-
Testing and CI:
integration_tests/: Cross-language integration tests.github/workflows/: GitHub Actions CI/CD workflowsci/: CI scripts and configurations
-
Build Configuration:
BUILD,WORKSPACE: Bazel configuration.bazelrc,.bazelversion: Bazel settingsMODULE.bazel: Bazel bzlmod dependency management- Various
pom.xml,package.json,Cargo.toml, etc.
-
licenses/: Third-party license reports and metadata
AGENTS.md: This file - AI coding guidanceCLAUDE.md: Claude Code specific instructionsCONTRIBUTING.md: Contribution guidelinesREADME.md: Project overview and quick start.gitignore: Git ignore patterns (includes build dirs)licenserc.toml: License header configurationdocs/guide/DEVELOPMENT.md: Environment setup and build notesdocs/cpp_debug.md: C++ debugging guide
Apache Fory is a blazingly-fast multi-language serialization framework that revolutionizes data exchange between systems and languages. By leveraging JIT compilation, code generation and zero-copy techniques, Fory delivers up to 170x faster performance compared to other serialization frameworks while being extremely easy to use.
Fory uses binary protocols for efficient serialization and deserialization. Fory designed and implemented multiple binary protocols for different scenarios:
- xlang serialization format:
- Cross-language serialize any object automatically, no need for IDL definition, schema compilation and object to/from protocol conversion.
- Support optional shared reference and circular reference, no duplicate data or recursion error.
- Support object polymorphism.
- Row format: A cache-friendly binary random access format, supports skipping serialization and partial serialization, and can convert to column-format automatically.
- Java serialization format: Highly-optimized and drop-in replacement for Java serialization.
- Python serialization format: Highly-optimized and drop-in replacement for Python pickle, which is an extension built upon xlang serialization format.
**docs/specification/** are the specification for the Fory protocol, please read those documents carefully and think hard and make sure you understand them before making changes to code and documentation.
- Primary references:
docs/compiler/index.md,docs/compiler/compiler-guide.md,docs/compiler/schema-idl.md,docs/compiler/type-system.md,docs/compiler/generated-code.md,docs/compiler/protobuf-idl.md,docs/compiler/flatbuffers-idl.md. - Location:
compiler/contains the Fory compiler, parser, IR, and code generators. - Install & CLI:
cd compiler && pip install -e .foryc --helpforyc schema.fdl --lang <langs> --output <dir>
- Generated code: Never edit generated files manually; update the
.fdl/.proto/.fbsand re-run the compiler. - IDL tests: Use
integration_tests/idl_tests/generate_idl.pyfor test codegen.- In
integration_tests/idl_tests, keep package names aligned with the IDL filename.
- In
- Protocol changes: Update
docs/specification/**and cross-language tests. - Language targets: FDL is the primary schema; protobuf/flatbuffers support should remain unchanged unless explicitly requested.
Fory serialization for every language is implemented independently to minimize the object memory layout interoperability, object allocation, memory access cost, thus maximize the performance. There is no code reuse between languages except for fory python, which reused code from fory c++.
-
fory-core: Java library implementing the core object graph serialization
java/fory-core/src/main/java/org/apache/fory/Fory.java: main serialization entry pointjava/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java: type resolution and serializer dispatchjava/fory-core/src/main/java/org/apache/fory/resolver/RefResolver.java: class for resolving shared/circular references when ref tracking is enabledjava/fory-core/src/main/java/org/apache/fory/serializer: serializers for each supported typejava/fory-core/src/main/java/org/apache/fory/codegen: code generators, provide expression abstraction and compile expression tree to java code and byte codejava/fory-core/src/main/java/org/apache/fory/builder: build expression tree for serialization to generate serialization codejava/fory-core/src/main/java/org/apache/fory/reflect: reflection utilitiesjava/fory-core/src/main/java/org/apache/fory/type: java generics and type inference utilitiesjava/fory-core/src/main/java/org/apache/fory/util: utility classes
-
fory-format: Java library implementing the core row format encoding and decoding
java/fory-format/src/main/java/org/apache/fory/format/row: row format data structuresjava/fory-format/src/main/java/org/apache/fory/format/encoder: generate row format encoder and decoder to encode/decode objects to/from row formatjava/fory-format/src/main/java/org/apache/fory/format/type: type inference for row formatjava/fory-format/src/main/java/org/apache/fory/format/vectorized: interoperation with apache arrow columnar format
-
fory-extensions: extension libraries for java, including:
- Protobuf serializers for fory java native object graph protocol.
- Meta compression based on zstd
-
fory-simd: SIMD-accelerated serialization and deserialization based on java vector API
java/fory-simd/src/main/java/org/apache/fory/util: SIMD utilitiesjava/fory-simd/src/main/java/org/apache/fory/serializer: SIMD accelerated serializers
-
fory-test-core: Core test utilities and data generators
-
testsuite: Complex test suite for issues reported by users and hard to reproduce using simple test cases
-
benchmark: Benchmark suite based on jmh
bazel dir provides build support for fory C++ and Cython:
bazel/cython_library.bzl:pyx_libraryrule for building Cython extensions
Dependencies are managed via MODULE.bazel using bzlmod (Bazel 8+).
cpp/fory/row: Row format data structurescpp/fory/meta: Compile-time reflection utilities for extract struct fields information.cpp/fory/encoder: Row format encoder and decodercpp/fory/util: Common utilitiescpp/fory/util/buffer.h: Buffer for reading and writing datacpp/fory/util/bit_util.h: utilities for bit manipulationcpp/fory/util/string_util.h: String utilitiescpp/fory/util/status.h: Status code for error handling
Fory python has two implementations for the protocol:
- Python mode: Pure python implementation based on
xlang serialization format, used for debugging and testing only. This mode can be enabled by settingENABLE_FORY_CYTHON_SERIALIZATION=0environment variable. - Cython mode: Cython based implementation based on
xlang serialization format, which is used by default and has better performance than pure python. This mode can be enabled by settingENABLE_FORY_CYTHON_SERIALIZATION=1environment variable. - Python mode and Cython mode reused some code from each other to reduce code duplication.
- Debug Struct Serialization: set
ENABLE_FORY_DEBUG_OUTPUT=1to enable detailed struct serialization/deserialization logs while debugging protocol behavior.
Code structure:
python/pyfory/serialization.pyx: Core serialization logic and entry point for cython mode based onxlang serialization formatpython/pyfory/_fory.py: Serialization entry point for pure python mode based onxlang serialization formatpython/pyfory/registry.py: Type registry, resolution and serializer dispatch for pure python mode, which is also used by cython mode. Cython mode use a cache to reduce invocations to this module.python/pyfory/serializer.py: Serializers for non-internal typespython/pyfory/includes: Cython headers forc++functions and classes.python/pyfory/resolver.py: resolving shared/circular references when ref tracking is enabled in pure python modepython/pyfory/format: Fory row format encoding and decoding, arrow columnar format interoperationpython/pyfory/buffer.pyx: Buffer for reading/writing data, string utilities. Used byserialization.pyxandpython/pyfory/formatat the same time.
Fory go provides reflection-based and codegen-based serialization and deserialization.
go/fory/fory.go: serialization entry pointgo/fory/resolver.go: resolving shared/circular references when ref tracking is enabledgo/fory/type.go: type system and type resolution, serializer dispatchgo/fory/slice.go: serializers forslicetypego/fory/map.go: serializers formaptypego/fory/set.go: serializers forsettypego/fory/struct.go: serializers forstructtypego/fory/string.go: serializers forstringtypego/fory/buffer.go: Buffer for reading/writing datago/fory/codegen: code generators, provide code generator to be invoked bygo:generateto generate serialization code to speed up the serialization.go/fory/meta: Meta string compression
Fory rust provides macro-based serialization and deserialization. Fory rust consists of:
- fory: Main library entry point
rust/fory/src/lib.rs: main library entry point to export API to users
- fory-core: Core library for serialization and deserialization
rust/fory-core/src/fory.rs: main serialization entry pointrust/fory-core/src/resolver/type_resolver.rs: type resolution and registrationrust/fory-core/src/resolver/metastring_resolver.rs: resolver for meta stringrust/fory-core/src/resolver/context.rs: context for reading/writingrust/fory-core/src/buffer.rs: buffer for reading/writing datarust/fory-core/src/meta: meta string compression, type meta encodingrust/fory-core/src/serializer: serializers for each supported typerust/fory-core/src/row: row format encoding and decoding
- fory-derive: Rust macro-based codegen for serialization and deserialization
rust/fory-derive/src/object: macro for serializing/deserializing structsrust/fory-derive/src/fory_row: macro for encoding/decoding row format
integration_tests contains integration tests with following modules:
- cpython_benchmark: benchmark suite for fory python
- graalvm_tests: test suite for fory java on graalvm.
- Note that fory use codegen to support graalvm instead of reflection, fory don't use
reflect-config.jsonfor serialization, this is the core advantage of compared to graalvm JDK serialization.
- Note that fory use codegen to support graalvm instead of reflection, fory don't use
- jdk_compatibility_tests: test suite for fory serialization compatibility between multiple JDK versions
- Performance First: Never introduce code that reduces performance without explicit justification
- Benchmark Required After Perf Optimizations: For every code change expected to improve performance, run the relevant benchmark immediately after applying the change and report the measured results (command + before/after numbers) in your response/PR.
- Performance Trace Log: For every performance-optimization round, append the hypothesis, code change, benchmark command, before/after numbers, and keep/revert decision to
tasks/perf_optimization_rounds.mdbefore moving to the next round. - Zero-Copy: Leverage zero-copy techniques when possible
- JIT Compilation: Consider JIT compilation opportunities
- Memory Layout: Optimize for cache-friendly memory access patterns
- Public APIs: Must be well-documented and easy to understand
- Error Handling: Implement comprehensive error handling with meaningful messages
- Type Safety: Use strong typing and generics appropriately
- Null Safety: Handle null values appropriately for each language
- Protocol Compatibility: Ensure serialization compatibility across languages
- Type Mapping: Understand type mapping between languages (see
docs/specification/xlang_type_mapping.md) - Endianness: Handle byte order correctly for cross-platform compatibility
- Version Compatibility: Maintain backward compatibility when possible
- Class registration: Keep class registration enabled unless explicitly requested; use custom class checkers or policies if disabling.
- Schema evolution: Prefer schema-consistent mode unless compatibility is required; update compatibility tests when changing schema rules.
- Unit Tests: Focus on internal behavior verification
- Integration Tests: Use
integration_tests/for cross-language compatibility - Language alignment and protocol compatibility: Run
org.apache.fory.xlang.CPPXlangTest,org.apache.fory.xlang.CSharpXlangTest,org.apache.fory.xlang.RustXlangTest,org.apache.fory.xlang.GoXlangTest, andorg.apache.fory.xlang.PythonXlangTestwhen changing xlang or type mapping behavior - Performance Tests: Include benchmarks for performance-critical changes
- API Changes: Update relevant documentation in
docs/ - Protocol Changes: Update specifications in
docs/specification/ - Examples: Provide working examples for new features
- Migration Guides: Document breaking changes and migration paths
- Read Specifications: Review relevant docs in
docs/specification/ - Understand Architecture: Study the language-specific implementation structure
- Check Existing Tests: Look at existing test patterns and coverage
- Review Related Issues: Check GitHub issues for context
- Follow Language Conventions: Respect each language's idioms and patterns
- Maintain Performance: Profile performance-critical changes
- Add Tests: Include appropriate tests for new functionality
- Update Documentation: Update docs for API changes
- Format Code: Use language-specific formatters before committing
- Use Python Mode: Set
ENABLE_FORY_CYTHON_SERIALIZATION=0for debugging - Check Specifications: Refer to protocol specs in
docs/specification/ - Cross-Language Testing: Use integration tests to verify compatibility
- Profile First: Use appropriate profilers for each language
- Memory Analysis: Check for memory leaks and allocation patterns
- Clean Builds: Use language-specific clean commands
- Dependency Issues: Check version compatibility
- Bazel Issues: Use
bazel clean --expungefor deep cleaning
- Java: Set
FORY_CODE_DIRto dump generated code;ENABLE_FORY_GENERATED_CLASS_UNIQUE_ID=falsekeeps stable generated class names. - Python: Use
cython --cplus -a pyfory/serialization.pyxfor annotated output;FORY_DEBUG=true python setup.py build_ext --inplacefor debug builds. - C++: See
docs/cpp_debug.md; generatecompile_commands.jsonwithbazel run :refresh_compile_commands. - Crash debugging: For macOS core dump setup, follow
CONTRIBUTING.md.
- C++: DTrace-based stack sampling is documented in
CONTRIBUTING.md.
- IntelliJ IDEA: Java modules target different bytecode levels (Java 8/11). Use a JDK 11+ project SDK and disable
--releaseif it blockssun.misc.Unsafeaccess (seeCONTRIBUTING.md).
ci.yml: Main CI workflow for all languagesbuild-native-*.yml: Mac/Window python wheel build workflowsbuild-containerized-*.yml: Containerized python wheel build workflows for linuxlint.yml: Code formatting and lintingpr-lint.yml: PR-specific checks
Use the GitHub CLI (gh) to inspect and fix CI failures:
# List all checks for a PR and their status
gh pr checks <PR_NUMBER> --repo apache/fory
# View failed job logs (get job ID from pr checks output)
gh run view <RUN_ID> --repo apache/fory --job <JOB_ID> --log-failed
# View full job logs
gh run view <RUN_ID> --repo apache/fory --job <JOB_ID> --log
# Example workflow for fixing CI errors:
# 1. List checks to find failing jobs
gh pr checks 2942 --repo apache/fory
# 2. Get the failed job logs (RUN_ID and JOB_ID from step 1)
gh run view 19735911308 --repo apache/fory --job 56547673283 --log-failed
# 3. Fix the issues based on error messages
# 4. Commit and push fixesCommon CI failures and fixes:
- Code Style Check: Run formatters (
clang-format,prettier,spotless:apply, etc.) - Markdown Lint: Run
prettier --write <file>for markdown files - C++ Build Errors: Check for missing dependencies or header includes
- Test Failures: Run tests locally to reproduce and fix
- PR titles: Follow Conventional Commits; CI uses
.github/workflows/pr-lint.ymlto enforce naming. - Performance changes: Use the
perftype and include benchmark data (seebenchmarks/java/README.md).
Use conventional commits with language scope:
feat(java): add codegen support for xlang serialization
fix(rust): fix collection header when collection is empty
docs(python): add docs for xlang serialization
refactor(java): unify serialization exceptions hierarchy
perf(cpp): optimize buffer allocation in encoder
test(integration): add cross-language reference cycle tests
ci: update build matrix for latest JDK versions
chore(deps): update guava dependency to 32.0.0