{"id":7647,"date":"2015-09-23T05:01:10","date_gmt":"2015-09-23T05:01:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/09\/23\/isaiah-transit-erlang\/"},"modified":"2015-09-23T05:01:10","modified_gmt":"2015-09-23T05:01:10","slug":"isaiah-transit-erlang","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/09\/23\/isaiah-transit-erlang\/","title":{"rendered":"isaiah\/transit-erlang"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/travis-ci.org\/isaiah\/transit-erlang.svg\" \/><\/p>\n<p>transit-format implementation in Erlang.<\/p>\n<p>Test and developed on Erlang\/OTP R17.<\/p>\n<p><em>NOTE:<\/em> Things are still experimental and subject to change.<\/p>\n<h2>Usage<\/h2>\n<pre><code>rebar get-deps compile\nerl -pa ebin deps\/*\/ebin\n<\/code><\/pre>\n<pre><code>A = transit:write(#{ =&gt; , 3 =&gt; 4}, #{ format =&gt; json }).\n%% =&gt; \ntransit:read(A, [{format, json}]).\n%% =&gt; #{ =&gt; , 3 =&gt; 4}\n\n%%% JSON Verbose mode\ntransit:write(#{ =&gt; , 3 =&gt; 4}, #{ format =&gt; json_verbose }).\n%% =&gt; \n\n%%% msgpack\ntransit:write(#{ =&gt; , 3 =&gt; 4}, #{ format =&gt; msgpack }).\n%% =&gt; \n<\/code><\/pre>\n<h2>Benchmarks<\/h2>\n<p>These benchmarks are run on a Lenovo Thinkpad W540 with a 16 Gigabyte RAM configuration and the following CPU core:<\/p>\n<pre><code>Intel(R) Core(TM) i7-4900MQ CPU @ 2.80GHz\n<\/code><\/pre>\n<p>Timings run 300 rounds of encoding of the file <code>transit-format\/examples\/0.8\/example.json<\/code> and then we divide down to get the encoder time for each round. This then forms the base benchmark.<\/p>\n<table>\n<tr>\n<th>Commit<\/th>\n<th>Test<\/th>\n<th>Timing ms<\/th>\n<\/tr>\n<tr>\n<td>3d3b04e<\/td>\n<td>JSON<\/td>\n<td>#{iso =&gt; 31.987, read =&gt; 9.976, write =&gt; 20.810}<\/td>\n<\/tr>\n<tr>\n<td>c976ce6<\/td>\n<td>JSON<\/td>\n<td>#{iso =&gt; 29.248, read =&gt; 8.883, write =&gt; 18.700}<\/td>\n<\/tr>\n<tr>\n<td>9d678c8<\/td>\n<td>JSON<\/td>\n<td>#{iso =&gt; 26.6893,read =&gt; 7.454,write =&gt; 18.178}<\/td>\n<\/tr>\n<tr>\n<td>3d3b04e<\/td>\n<td>MsgPack<\/td>\n<td>#{iso =&gt; 15.911, read =&gt; 4.901, write =&gt; 12.072}<\/td>\n<\/tr>\n<tr>\n<td>c976ce6<\/td>\n<td>MsgPack<\/td>\n<td>#{iso =&gt; 11.713, read =&gt; 3.258, write =&gt; 9.051}<\/td>\n<\/tr>\n<tr>\n<td>9d678c8<\/td>\n<td>MsgPack<\/td>\n<td>#{iso =&gt; 11.2637, read =&gt; 2.8620, write =&gt; 9.0897}<\/td>\n<\/tr>\n<tr>\n<td>3d3b04e<\/td>\n<td>JSON_Verbose<\/td>\n<td>#{iso =&gt; 34.236, read =&gt; 9.724, write =&gt; 25.638}<\/td>\n<\/tr>\n<tr>\n<td>c976ce6<\/td>\n<td>JSON_Verbose<\/td>\n<td>#{iso =&gt; 36.613, read =&gt; 9.572, write =&gt; 27.120}<\/td>\n<\/tr>\n<tr>\n<td>9d678c8<\/td>\n<td>JSON_Verbose<\/td>\n<td>#{iso =&gt; 33.36954, read =&gt; 8.59574, write =&gt; 29.23906}<\/td>\n<\/tr>\n<\/table>\n<p>Some important timings are that <code>jsx<\/code> decodes in 5.630 ms and <code>msgpack<\/code> decodes in 0.930 ms. These are therefore the minimum timings and the rest is transit-specific overhead of decoding.<\/p>\n<h2>Current limitations<\/h2>\n<ul>\n<li>Points-in-time before the date 1\/1 1970 are not encoded and decoded correctly.<\/li>\n<\/ul>\n<h2>Default type mapping<\/h2>\n<p>We currently handle the types in the given table with the given mappings.<\/p>\n<p><em>Rationale for the mapping<\/em>: The problem we face in Erlang w.r.t transit is that we can\u2019t really map external data directly into <code>atom()<\/code> types. The reason is the atom-table is limited and an enemy can easily outrun it. Other language implementations are not with this limit, so they will just use keywords as they go along, ignoring all limitations of them in Erlang. Thus, we opt for a solution where the low-level mapping is to map a lot of things into binary types, but tag them as we do so to discriminate them.<\/p>\n<p>We chose to handle a \u201cnaked\u201d <code>binary()<\/code> as an UTF-8 string.<\/p>\n<h3>Mapping override<\/h3>\n<p>In order to handle data in a neat Erlang-esque way, it is possible to supply a translation table in the decoder direction. This table is used to handle scalar types and map them into other data. The intended use is to support <code>binary() \u2192 atom()<\/code> conversion for keywords and symbols. But it also useful for direct decoding of other types.<\/p>\n<pre><code>9&gt; transit:write({kw, }).<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>transit-format implementation in Erlang. Test and developed on Erlang\/OTP R17. NOTE: Things are still experimental and subject to change. Usage rebar get-deps compile erl -pa ebin deps\/*\/ebin A = transit:write(#{ =&gt; , 3 =&gt; 4}, #{ format =&gt; json }). %% =&gt; transit:read(A, [{format, json}]). %% =&gt; #{ =&gt; , 3 =&gt; 4} %%% JSON [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7647","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7647"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7647\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}