Diff two ledger snapshots
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
sortBy → map → concat 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
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Native wins
Peak memory Native wins
N = 500,000
Time Native wins
Peak memory FxDart wins
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.