Fetch profiles, two at a time
Requirement
Fetch six user profiles from a (simulated) API, but never more than two requests in flight at once — the API rate-limits. Results must come back in the original order. To prove the limit held, the fake fetch counts how many requests overlap and both versions print the maximum observed.
This is the task plain Dart has no primitive for.
Future.wait runs everything at once;
batching into pairs wastes time waiting for the slower of each pair;
doing it right means writing a worker pool by hand — index bookkeeping,
a shared cursor, pre-sized result slots. FxDart's
.concurrent(2) is that worker pool, as one word: as each
request finishes the next one starts, and order is preserved.
Expected output
user#1, user#2, user#3, user#4, user#5, user#6 max requests in flight: 2
Side by side
Native Dart
FxDart
Why they differ
The two versions print the same thing — the difference is what you had to write and what you now have to maintain. The native worker pool is real production boilerplate (and easy to get subtly wrong: off-by-one on the shared cursor, forgetting to pre-size the results list, losing ordering). In the FxDart version the concurrency policy is a single chain step, so changing the limit — or removing it — touches one number instead of the function's whole shape.
Benchmark
Async case: the headline scale is N = 100,000, not 1,000,000. Every element costs an event-loop turn on both sides, so a million real awaits would measure Dart's event loop for minutes — not the pipeline. Delays are zero-length and the example's concurrency limit is kept; what the bars compare is the pipeline machinery.
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Native wins
Peak memory FxDart wins
N = 100,000
Time Native wins
Peak memory Tie
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.