Skip to content

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.

Co-authored-by: Andrea Leopardi <an.leopardi@gmail.com>
@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