Skip to content

Add :sort_maps to Inspect.Opts.custom_options #12404

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

Merged
merged 2 commits into from
Feb 16, 2023

Conversation

sabiwara
Copy link
Contributor

Add :sort_maps to Inspect.Opts.custom_options in order to make inspect tests deterministic and fix them in OTP26.

Screenshot 2023-02-16 at 9 36 24

Note: other tests like Enum tests also need to be fixed, will do it in a separate PR.

list = Map.to_list(map)
list =
if Keyword.get(opts.custom_options, :sort_maps) do
map |> Map.to_list() |> :lists.sort()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I benched this with the new :maps.iterator(map, :ordered): sabiwara/elixir_benches@71055e9, but this implementation has the benefit of:

  • being faster or equivalent
  • using half as much memory
  • work on OTP < 26

So I went with this one instead.

@josevalim josevalim merged commit 9cdff30 into elixir-lang:main Feb 16, 2023
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@sabiwara sabiwara deleted the inspect-sort-maps branch February 16, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants