Simon Jakobi pushed to branch wip/sjakobi/udfm-placement at Glasgow Haskell Compiler / GHC
Commits:
-
9da8424e
by Simon Jakobi at 2026-07-02T17:59:23+02:00
1 changed file:
Changes:
| ... | ... | @@ -351,11 +351,12 @@ nonDetStrictFoldUDFM k z (UDFM m _i) = foldl' k' z m |
| 351 | 351 | -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 352 | 352 | -- Deterministic iteration orders elements by insertion tag, and any such
|
| 353 | 353 | -- ordering must inspect every element's tag before it can emit the first
|
| 354 | --- element. So even the head of the result costs a full O(n) traversal of the
|
|
| 355 | --- map -- the iteration is not incremental, and laziness in the result list (see
|
|
| 356 | --- Note [Placement sort in eltsUDFM]) saves allocation for undemanded
|
|
| 357 | --- elements, not that up-front traversal. #27459 shows this cost biting in
|
|
| 358 | --- consumers that demanded only the head.
|
|
| 354 | +-- element. So even the head of the result costs a full traversal of the map
|
|
| 355 | +-- plus the allocation of an O(n)-sized array -- or, on the fallback path,
|
|
| 356 | +-- O(n log n) cons cells (see Note [Placement sort in eltsUDFM]). Laziness in
|
|
| 357 | +-- the result list only avoids allocating for elements that are never
|
|
| 358 | +-- demanded; it does not make the iteration incremental. #27459 shows this
|
|
| 359 | +-- cost biting in consumers that demanded only the head.
|
|
| 359 | 360 | --
|
| 360 | 361 | -- So: to test for emptiness, use isNullUDFM rather than null on eltsUDFM;
|
| 361 | 362 | -- for order-oblivious queries, prefer short-circuiting anyUDFM/allUDFM; and
|