Actually with just a minimal change in encode.c, that NIF works in R13B04. I made an attempt to make it work under R13B03 as well but haven't succeed:
https://github.com/fdmanana/eep0018/commit/4b379372bf5c4b21dd13c6fd1b261bedbfd45131 Making the stubs call mochijson2 would be ok as well. +1 for introducing NIFs in trunk. On Fri, Mar 25, 2011 at 6:49 AM, Damien Katz <dam...@apache.org> wrote: > Nice. Reading that it looks like at runtime init code can check the Erlang > version and not attempt to load the nif library on Erlang old versions, > falling back to pure erlang code there. Cool. > > So then the only remaining problem is the compiling and linking on the > older Erlangs where nifs aren't available or are incompatible. We'll need > to add something to the build system to deal with that so we don't get > build failures. > > -Damien > > > > On 3/24/11 11:37 PM, "Adam Kocoloski" <kocol...@apache.org> wrote: > >>On Mar 24, 2011, at 9:01 PM, Damien Katz wrote: >> >>> After discovering the huge amounts of CPU we spend parsing and encoding >>> JSON, I've been working on getting big num support into Paul Davis's >>>JSON >>> NIF parser so we can include it in CouchDB a get nice performance win. >>>I'm >>> really loving the NIF interface and it's potential to give us >>>performance >>> boosts in CouchDB's CPU intensive areas. With the NIF support, we are >>> going to see a much faster CouchDB. >>> >>> However, the problem is they don't work pre R14B. >>> >>> So to include NIF functions and get the gains, either we need to raise >>>the >>> minimal Erlang version of trunk CouchDB for R14B, OR have both a slow >>> erlang version of the NIF for older version, and fast NIF version for >>> newer versions and a way to load the different versions. Maybe the NIF >>> system has that stuff built in, or maybe we can do it somehow with the >>> build system. >>> >>> Since this is trunk, we'll be raising the minimal version of something >>> like 1.2, not 1.0.3, for example. Anyway, wanted to get that out there >>>and >>> see what people think about how to handle it. >>> >>> -Damien >> >>I have no qualms about raising the minimum required Erlang version, but I >>thought NIFs naturally allowed for pure-Erlang alternative >>implementations. From http://www.erlang.org/doc/tutorial/nif.html: >> >>> [A]ll NIFs of a module must have an Erlang implementation as well. >>>Normally these are minimal stub implementations that throw an exception. >>>But it can also be used as fallback implementations for functions that >>>do not have native implemenations on some architectures. >> >>Regards, Adam >> > > > -- Filipe David Manana, fdman...@gmail.com, fdman...@apache.org "Reasonable men adapt themselves to the world. Unreasonable men adapt the world to themselves. That's why all progress depends on unreasonable men."