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

Log alert digest by service and severity

FxDart wins

Requirement

From a stream of service logs (data in the code), keep only WARN and ERROR lines and render an indented digest: services sorted by alert count, under each service the severity with its count, under each severity the distinct messages. The header line carries the overall ERROR/WARN totals. Both versions must print the digest under Expected output.

Expected output
Alert digest — ERROR 4, WARN 5
api (4)
  ERROR x2
    - timeout calling billing
  WARN x2
    - slow query 1.2s
    - disk 85% full
auth (3)
  ERROR x1
    - bad signature
  WARN x2
    - token near expiry
billing (2)
  ERROR x1
    - invoice 442 failed
  WARN x1
    - retrying charge

Side by side

Native Dart

FxDart

Why they differ

An indented digest is a tree flattened to lines, and flatMap is exactly that flattening: the outer groupBy + sortBy + flatMap emits a header plus its children per service, the inner flatMap does the same per severity, and uniq handles the repeated messages where they occur. countBy gives the header totals in one word. The native version is three nested for loops writing into one shared body list, plus a hand-rolled counting map and a seen-set for dedupe — the tree shape is real in both versions, but only one of them lets you read it off the indentation of the code itself.

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 25 µs

Peak memory Tie

Native Dart 16.5 MB
FxDart 16.5 MB

N = 10,000

Time Tie

Native Dart 1.46 ms
FxDart 1.39 ms

Peak memory Tie

Native Dart 17.9 MB
FxDart 18.1 MB

N = 1,000,000

Time Tie

Native Dart 174.1 ms
FxDart 174.4 ms

Peak memory Native wins

Native Dart 213.2 MB
FxDart 239.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.