Skip to content

Refactor and optimize two#521

Closed
sjakobi wants to merge 10 commits into
masterfrom
sjakobi/two-idx2
Closed

Refactor and optimize two#521
sjakobi wants to merge 10 commits into
masterfrom
sjakobi/two-idx2

Conversation

@sjakobi

@sjakobi sjakobi commented Oct 16, 2025

Copy link
Copy Markdown
Member

TODO:

  • Create a type synonym ShiftedHash with utilities like shiftSH, maskSH etc
  • Check the Core

This reduces the core size for the inner loop of two by 10 terms.
This results in a ~10% reduction in Code size for each of the insert
variants.

Closes #447.
* Use the "shifted hash" approach.
* Create a variant `two'` that can be used to address #468.
Comment thread Data/HashMap/Internal.hs Outdated
@sjakobi

sjakobi commented Oct 19, 2025

Copy link
Copy Markdown
Member Author

So far, I'm seeing speedups of 2–4% on benchmarks for fromList and union with 100–10.000 elements.

@sjakobi sjakobi marked this pull request as ready for review October 19, 2025 17:12
@sjakobi sjakobi marked this pull request as draft October 19, 2025 17:53
Comment thread Data/HashMap/Internal.hs
Comment on lines +964 to +967
-- | This function lives at the top-level so 'two' and `two'` can be inlined
-- without inlining this loop.
two_go :: ShiftedHash -> HashMap k v -> ShiftedHash -> HashMap k v -> ST s (HashMap k v)
two_go !sh1 t1 !sh2 t2

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Having this loop at the top-level nicely reduces the bloat, but functions like union seem to get slower by up to 4% :/

@sjakobi

sjakobi commented Oct 19, 2025

Copy link
Copy Markdown
Member Author

I've extracted the (in my mind) unquestionable changes to #524.

I'll have another go at goDifferentHash etc once that is merged.

@sjakobi sjakobi closed this Oct 19, 2025
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.

1 participant