Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize maps:merge/2 of small maps #7004

Merged
merged 3 commits into from
Mar 17, 2023

Conversation

sverker
Copy link
Contributor

@sverker sverker commented Mar 9, 2023

Save heap space when any of the maps have all the keys.

  • If one of the maps have all the keys we reuse its key tuple.
  • If both maps have all the keys we prefer a literal key tuple.

ok, here is the new deal:

maps:merge(A,B) % map B has priority and will supersede values in map A

  • If only map B has all the keys, return the entire map B as-is.
  • If only map A has all the keys, reuse its key tuple.
  • If both have all the keys return B, but if A has a literal key tuple and B does not, first mutate map B to use A's key tuple.

@sverker sverker added team:VM Assigned to OTP team VM enhancement labels Mar 9, 2023
@sverker sverker self-assigned this Mar 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

CT Test Results

       3 files     133 suites   52m 46s ⏱️
1 547 tests 1 496 ✔️ 51 💤 0
1 964 runs  1 894 ✔️ 70 💤 0

Results for commit 8a15f4d.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@sverker sverker added the testing currently being tested, tag is used by OTP internal CI label Mar 10, 2023
@sverker sverker force-pushed the sverker/maps-merge-opt branch 3 times, most recently from fc952ec to 27cf8d7 Compare March 15, 2023 22:35
If 2nd map has all keys return it as-is.
If 1st map has all keys reuse its key tuple.
If both maps have all the keys and 1st map have a literal key tuple
but 2nd map does not, then we mutate 2nd map with literal key tuple
before returning it.
@sverker sverker merged commit d7c9c8c into erlang:master Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant