Skip to content

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Dec 5, 2025

No description provided.

Comment on lines +1187 to +1188
st' | st' `ptrEq` st -> t
| isLeafOrCollision st' && A.length ary == 1 -> st'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change slightly reduces the code size by moving the pointer-eq check to an earlier point. Only afterwards do we differentiate the alternatives for Leaf, Collision etc.

@sjakobi sjakobi marked this pull request as ready for review December 9, 2025 01:27
| otherwise
= case A.index# ary i of
deleteFromSubtree :: Eq k => Shift -> Hash -> k -> HashMap k v -> HashMap k v
deleteFromSubtree !s !h !k = \case
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit unhappy about the forcing of keys. The upside is that key types likes Int and ShortByteString are unboxed. The downside is that key types that can't be unboxed to an unlifted representation are unnecessarily evaluated again and again.

Maybe we can use Strict# for this, once it's released?!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where/why are keys getting re-forced?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are forced once for each subtree we check. So probably ~1–5 times for a typical HashMap.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're only forcing the key to get it to unbox, right? So you need the function to be strict in the key when the key is an unboxable type. The function is "naturally" strict in the key for (non-trivial, non-pathological) unboxable types whenever its hash is present in the map (because you'll test key equality). So I believe you should only need to add explicit strictness in the key where you discover that its hash is not in the map.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! I agree with your reasoning but I doubt that GHC's strictness analyser could be convinced to believe it too! 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet it can, but I need to go back to sleep.

@sjakobi sjakobi merged commit 7be935f into master Dec 11, 2025
10 checks passed
@sjakobi sjakobi deleted the sjakobi/refactor-delete branch December 11, 2025 05:21
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