When using term_to_binary
to convert function to external term format binary, I found that binary size in Elixir is much smaller than the one in Erlang. I was expecting they should be close. I am curious why ?
Following are the results:
In Elixir iex:
Erlang/OTP 21 [erts-10.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Interactive Elixir (1.7.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> byte_size(:erlang.term_to_binary(fn -> 1 end))
135
iex(2)> byte_size(:erlang.term_to_binary(fn -> 1 end, minor_version: 0))
135
iex(3)> byte_size(:erlang.term_to_binary(fn -> 1 end, minor_version: 1))
135
iex(4)> byte_size(:erlang.term_to_binary(fn -> 1 end, minor_version: 2))
129
In Erlang shell:
Erlang/OTP 21 [erts-10.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Eshell V10.0.4 (abort with ^G)
1> byte_size(term_to_binary(fun() -> 1 end)).
709
2> byte_size(term_to_binary(fun() -> 1 end, [{minor_version, 0}])).
709
3> byte_size(term_to_binary(fun() -> 1 end, [{minor_version, 1}])).
709
4> byte_size(term_to_binary(fun() -> 1 end, [{minor_version, 2}])).
684