Creating structures: new vs modify

Erlang maps can share a tuple of keys to reduce memory usage.
I found that when creating identical structures using the %Struct{...} syntax, the created structures do not share keys tuple.
But if you modify an already created default structure instead of creating a new one, the keys will be shared.

defmodule Struct do
  defstruct [:a, :b, :c, :d]
end

defmodule Test do
  def run() do
    Enum.map(0..1000, &%Struct{a: &1, b: &1, c: &1, d: &1})
    |> :erts_debug.size()
    |> IO.puts()

    Enum.map(0..1000, &%{%Struct{} | a: &1, b: &1, c: &1, d: &1})
    |> :erts_debug.size()
    |> IO.puts()
  end
end

Test.run()

Output

16016
10016

Is that %Struct{...} behavior a flaw or is it intentional?

When creating maps it’s probably cheaper to not look at other maps in memory to see if their keys align. For updates the beam however knows that the keys are the same.

The beam is completely unaware of the fact that structs in elixir enforce the same set of keys.