Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

Merchants in first-visit order

FxDart wins

Requirement

From a month of transactions, list each merchant once, in the order it was first visited — repeat visits must not move a merchant later in the list. The data is in the code below; both versions must print the line shown under Expected output.

Expected output
Cafe Aroma, Metro Card, Green Grocer, Noodle Bar

Side by side

Native Dart

FxDart

Why they differ

The tempting native one-liner is toSet().toList() — and it would even print the right thing, because Dart's default set happens to be insertion-ordered. But the Iterable.toSet contract promises no order at all, so code whose requirement is first-visit order shouldn't lean on it; the honest native version is a seen-set loop with two collections and an if. FxDart's uniq makes the guarantee part of the name: it lazily keeps the first occurrence of each element, by contract, as one chain step after map.

Benchmark

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

N = 100

Time Tie

Native Dart 1.4 µs
FxDart 1.7 µs

Peak memory Tie

Native Dart 16.5 MB
FxDart 16.5 MB

N = 10,000

Time Tie

Native Dart 151 µs
FxDart 168 µs

Peak memory Tie

Native Dart 17.0 MB
FxDart 17.0 MB

N = 1,000,000

Time Native wins

Native Dart 23.8 ms
FxDart 26.2 ms

Peak memory Tie

Native Dart 116.6 MB
FxDart 116.0 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.