Skip to content

feat(benchmark): add benchmarking framework to establish an FFI migration baseline#778

Open
WutangNailao wants to merge 6 commits into
brendan-duncan:mainfrom
WutangNailao:main
Open

feat(benchmark): add benchmarking framework to establish an FFI migration baseline#778
WutangNailao wants to merge 6 commits into
brendan-duncan:mainfrom
WutangNailao:main

Conversation

@WutangNailao
Copy link
Copy Markdown

Background

To support the upcoming FFI migration in image, we need a repeatable and measurable performance baseline first, so we can evaluate before/after changes with a consistent methodology.

What’s included

This PR introduces benchmark infrastructure:

  • Adds a benchmark runner, case registry, API collector, report generator, and image comparison utility.
  • Adds multi-resolution samples and standardized output (benchmark/results.json).
  • Aligns benchmark cases with exported API symbols to enable coverage-oriented benchmarking.

Usage Examples

# 1) Run benchmarks (generates benchmark/api_manifest.json and benchmark/results.json)
dart run benchmark/runner.dart

# 2) Generate Markdown report (default output: benchmark/benchmark_report.md)
dart run benchmark/report.dart

# 3) Generate report with explicit input/output paths
dart run benchmark/report.dart benchmark/results.json benchmark/benchmark_report.md

# 4) Compare two PNG outputs (optional tolerance, default: 0)
dart run benchmark/compare.dart a.png b.png
dart run benchmark/compare.dart a.png b.png 2

Why this matters

  • Establishes a stable performance baseline for future FFI work.
  • Enables apples-to-apples before/after performance comparisons.
  • Reduces regression debugging cost during migration.

Follow-ups

  • Reuse the same benchmark suite in the FFI branch to produce directly comparable results.
  • Gradually integrate benchmark runs into CI for continuous performance tracking.

- add benchmark runner, case registry, API collector, report generator, and image comparator
- add multi-resolution benchmark sample data and generated benchmark artifacts
- update .pubignore to exclude benchmark/ from published package
mrwutangnailao-debug and others added 3 commits March 16, 2026 00:22
Introduce an optional Rust-backed FFI backend for selected image transform
operations and document how native acceleration is distributed and consumed.

This change adds a native transform backend entry point to the public API and
updates `copyCrop` and `copyResize` to opportunistically use native
implementations when the requested operation matches supported fast paths.
When native acceleration is unavailable or the operation requires unsupported
features, both methods transparently fall back to the existing Dart
implementations to preserve current behavior and compatibility.

Changes included:
- document optional native acceleration support in README
- clarify that precompiled native binaries are shipped with the package
- note that a local Rust toolchain is not required for standard package usage
- mention iOS XCFramework distribution for combined device/simulator support
- export `transform_backend.dart` from the main library surface
- refactor `copyCrop` to delegate to `tryNativeCopyCrop` for non-rounded crops
- move Dart crop logic into `copy_crop_dart.dart` as the fallback path
- refactor `copyResize` to delegate to `tryNativeCopyResize` for supported
  fixed-size resize operations
- move Dart resize logic into `copy_resize_dart.dart` as the fallback path
- add FFI/code asset dependencies required for native integration
- add `ffigen` as a dev dependency for native binding generation
- update SDK constraint to `^3.10.0`

Behavior notes:
- native crop is only attempted when `radius == 0`
- native resize is only attempted for explicit `width` + `height` requests
  without aspect-preserving layout or background fill requirements
- all unsupported cases continue to use the pure Dart implementation
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