Diff two ledger snapshots

FxDart wins

Requirement

Two snapshots of the same ledger (data in the code): a sync happened in between, and entries were added and removed. Print a diff keyed by entry id — + lines for added entries, - lines for removed ones (each section sorted by id), the count of unchanged entries, and the net change in total amount. Both versions must print the diff under Expected output.

Expected output
Ledger diff (5 -> 5 entries)
+ t6 Noodle Bar $18.90
+ t7 Pharmacy $22.40
- t3 Metro card $30.00
- t4 Cinema $15.00
= 3 unchanged entries
Net change: -$3.70

Side by side

Native Dart

FxDart

Why they differ

Diffing is set algebra over a key, and FxDart ships the vocabulary: differenceBy called both ways gives added and removed, intersectionBy gives the unchanged entries — three declarations that read like the definition of a diff. The sortBymapconcat pipeline then renders both sections in one expression. Native Dart has set operations only for Set itself, not for "by this key of these objects", so the honest version manually projects id sets and writes a negated contains filter per direction — easy to get backwards, and the intent ("what's in B but not A?") lives in the predicate's polarity rather than in a function name.

Benchmark

Apple M1 Max, 32 GB RAM · Dart 3.12.2 (AOT-compiled) · 2026-08-24

N = 100

Time Tie

Native Dart 21 µs
FxDart 23 µs

Peak memory Tie

Native Dart 16.5 MB
FxDart 16.5 MB

N = 10,000

Time Native wins

Native Dart 2.37 ms
FxDart 3.16 ms

Peak memory Native wins

Native Dart 26.0 MB
FxDart 31.2 MB

N = 500,000

Time Native wins

Native Dart 223.4 ms
FxDart 261.0 ms

Peak memory FxDart wins

Native Dart 182.1 MB
FxDart 171.8 MB

Bars are medians of repeated timed iterations in fresh processes per side (small N is batched for timer resolution). Sides within 5% of each other — or within 0.6 ms, a difference no person can perceive — count as a tie; close relative races are re-measured up to 5 runs. In an app, anything under a few milliseconds is invisible to the user regardless of which bar is shorter. Memory is peak process RSS. The Dart VM and the dataset are identical on both sides, so the difference between the two bars is what the pipeline itself holds onto.