Skip to content

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Nov 13, 2025

Core size reduction with GHC 9.12.2:

  • Lazy.unionWithKey: 2256 terms -> 1286
  • Strict.unionWithKey: 2101 terms -> 1167
  • union @Int in fine-grained: 1245 terms -> 1134

Core size reduction with GHC 9.12.2:

* Lazy.unionWithKey: 2256 terms -> 1286
* Strict.unionWithKey: 2101 terms -> 1167
* union @int in fine-grained: 1245 terms -> 1134
@treeowl
Copy link
Collaborator

treeowl commented Nov 13, 2025

Does GHC not create join points to common up the futures of those computations? What if we do that manually?

@sjakobi
Copy link
Member Author

sjakobi commented Nov 13, 2025

Does GHC not create join points to common up the futures of those computations?

It does in some cases.

In Lazy.unionWithKey, the main savings stem from some inner worker functions not being generated:

$s$wgo [Occ=LoopBreaker]
          :: Word#
             -> SmallArray# (Leaf k v) -> Int# -> HashMap k v -> HashMap k v

$s$wgo1 [Occ=LoopBreaker]
          :: Word#
             -> SmallArray# (Leaf k v) -> HashMap k v -> Int# -> HashMap k v

$s$wgo2 [Occ=LoopBreaker]
          :: Word# -> k -> v -> HashMap k v -> Int# -> HashMap k v

I suspect these are the result of -fliberate-case?!

@sjakobi
Copy link
Member Author

sjakobi commented Nov 13, 2025

I can't find a significant difference in the fine-grained benchmarks for union and differenceWith.

@treeowl
Copy link
Collaborator

treeowl commented Nov 13, 2025

I don't know how if at all we can control case liberation, but what happens if we just do the join point thing?

whatever t@(Leaf h _) = whatever' h t
whatever t@(Collision h _) = whatever' h t

@sjakobi
Copy link
Member Author

sjakobi commented Nov 13, 2025

I don't know how if at all we can control case liberation, but what happens if we just do the join point thing?

Like this? 74b4d86

This also suppresses the case liberation. Performance might be slightly better, although the current benchmarks shouldn't exercise these code paths much.

@treeowl
Copy link
Collaborator

treeowl commented Nov 13, 2025

Yes, like that, though I'd call it something more like fullVsLeafOrCollision. Along with whatever marginal performance benefit it has, that also removes the pesky "impossible" error, so I'd call it a cleanliness win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants