[erlang-patches] Patch for term_to_binary() stack overflow

Bjorn Gustavsson <>
Fri Mar 20 14:40:35 CET 2009


On Tue, Mar 10, 2009 at 11:40 PM, Jan Lehnardt <> wrote:
> Dear OTP Team,
>
> https://issues.apache.org/jira/browse/COUCHDB-275 describes an issue
> with Erlang's term_to_binary() BIF and includes a patch. The core of the
> issue is that term_to_binary() is implemented in a recursive C function
> that blows the stack when converting deeply nested term structures. We
> see this when people try to read deeply nested JSON structures that we
> convert from Erlang terms to binaries representing JSON for delivery.
>
> The easiest way to reproduce this is
>
> term_to_binary(lists:foldl(fun(E,A) -> [E, A] end, [], lists:seq(1,
> 100000))).
>

We have now removed deep recursion from the implementation of term_to_binary/1
(will appear in the R13B release). Seems to be somewhat faster than
before, at least
for deeply nested terms.

/Bjorn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-patches mailing list