# Jiffy 2.1.0

**URL:** <https://erlangforums.com/t/jiffy-2-1-0/6169>\
**Category:** Library Updates\
**Tags:** jiffy, to-catch-all\
**Created:** [November 24, 2026, 11:02pm UTC](https://erlangforums.com/t/jiffy-2-1-0/6169 "2026-11-24T23:02:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickva](https://erlangforums.com/user_avatar/erlangforums.com/nickva/32/578_2.png) [@nickva](https://erlangforums.com/u/nickva)\
**Post date:** [November 24, 2026, 11:02pm UTC](https://erlangforums.com/t/jiffy-2-1-0/6169/1 "2026-11-24T23:02:32Z")

</div>

> [@Jiffy - JSON NIF for Erlang](https://erlangforums.com/t/jiffy-json-nif-for-erlang/5621):
>
> Jiffy - JSON NIF for Erlang Jiffy is a JSON NIF library that focuses on correctness over performance. It’s not the fastest JSON library for Erlang in standard benchmarks, but it endeavors to be as fast as possible while affecting total system performance as little as possible. Usage Example Jiffy has a simple API 1\> jiffy:decode(\<\<"{\"foo\": \"bar\"}"\>\>). {[{\<\<"foo"\>\>,\<\<"bar"\>\>}]} 2\> Doc = {[{foo, [\<\<"bing"\>\>, 2.3, true]}]}. {[{foo,[\<\<"bing"\>\>,2.3,true]}]} 3\> jiffy:encode…

# Changes

- 
### Add max\_depth decode option [#314](https://github.com/davisp/jiffy/pull/314)

`{max_depth, N}` decodes top `N` levels of nested objects and arrays. Anything below is validated but returns as `{json, Binary}`. Coincidentally, that shape is what the encoder already takes as pre-encoded JSON. So, a router can decode the top level, look at a few fields and encode the result to pass it along, without building and re-encoding the nested bodies:

```erlang
1> Msg = ~'{"to":"node2","body":{"k":[1,2]}}'.
2> Top = jiffy:decode(Msg, [return_maps, {max_depth, 1}]).
#{<<"body">> => {json,<<"{\"k\":[1,2]}">>},<<"to">> => <<"node2">>}
3> jiffy:encode(Top#{~"hops" => 1}).
[<<"{\"to\":\"node2\",\"hops\":1,\"body\":">>,<<"{\"k\":[1,2]}">>,<<"}">>]

```

The nested body goes into the output iolist as is. Decoding the top level and re-encoding takes about a quarter of the time of a full decode and encode on the benchmark inputs. It also leaves next to nothing on the heap: `twitter.json` is 123127 words fully decoded and 37 words with `{max_depth, 1}`.

- 
### Lazy resource creation for faster small object encoding/decoding [#315](https://github.com/davisp/jiffy/pull/315)

Profiling showed a lot of time (comparatively) spent allocating the NIF resource. We use the resource to hold state when we yield (and we do want to keep yielding and not use dirty schedulers as those are a limited resource!). But we can have our cake and eat it too if we just use the C stack until we have to yield. This way tiny objects may never create the resource at all.

Encoding something silly like `{"ok": true}` takes 145 ns now and took 700 ns before, decoding it takes 130 ns instead of 600 ns. A 200 byte object encodes in 1 us instead of 1.5 us. Small objects also scale with the number of cores now: on an 80 core box 2.0.2 topped out below 10 million `{"ok": true}` decodes per second no matter how many processes were at it, 2.1.0 does about 200 million with 40 processes.

- 
### Improve reductions counting [#317](https://github.com/davisp/jiffy/pull/317), [#318](https://github.com/davisp/jiffy/pull/318)

The scheduler handles yielding, checks timers, wakes up other schedulers and rebalances based on reduction counts, not wall clock. So a messed up reduction count will mess up scheduling for everyone else on the node. There were issues there like the last value of a document wasn’t counted, so a document which is one long string was free, and pre-encoded `{json, ...}` values and bignums were counted either twice or not at all.

# Other Changes

- Simplify decoder stack [#312](https://github.com/davisp/jiffy/pull/312) and fast forward unescaped runs in the decoder [#313](https://github.com/davisp/jiffy/pull/313). Decoding long strings is up to 3x faster
- Use `enif_term_type()` in the encoder [#310](https://github.com/davisp/jiffy/pull/310). The minimum supported OTP version is now **22** (sorry Erlang 21 fans 😞 )
- Update ffc.h [#307](https://github.com/davisp/jiffy/pull/307) and use `enif_make_reverse_list` for decoding arrays [#311](https://github.com/davisp/jiffy/pull/311)

Overall decoding and encoding are 10-15% faster than 2.0.2 on [bench](https://github.com/nickva/bench.git).

# Scheduling Benchmark Update

Updated scheduling benchmark, this time run in a more server-like environment (80 CPU, Linux, x86\_64)

```shell
./bench_scheduling.sh
...
scheduler responsiveness check
  input: citm-catalog.json duration: 2000
  schedulers: 80 online
  impls: json, jiffy, glazer, jsone, jsx

[json]
  1x encdec n=55 p50=18.4ms p95=19.9ms p99=20.5ms max=24.6ms
  80x encdec n=480 p50=182.4ms p95=234.1ms p99=247.0ms max=280.2ms
  160x encdec n=464 p50=420.6ms p95=517.6ms p99=572.0ms max=618.5ms

[jiffy]
  1x encdec n=122 p50=8.6ms p95=9.2ms p99=9.9ms max=15.0ms
  80x encdec n=1430 p50=53.2ms p95=104.8ms p99=121.1ms max=145.0ms
  160x encdec n=1314 p50=114.3ms p95=228.3ms p99=261.0ms max=310.3ms

[glazer]
  1x encdec n=316 p50=3.0ms p95=3.7ms p99=6.1ms max=11.7ms
  80x encdec n=236 p50=413.7ms p95=439.0ms p99=453.4ms max=459.6ms
  160x encdec n=160 p50=976.8ms p95=1449.3ms p99=1451.1ms max=1451.6ms

[jsone]
  1x encdec n=36 p50=27.3ms p95=34.1ms p99=36.8ms max=37.8ms
  80x encdec n=325 p50=240.0ms p95=313.4ms p99=332.8ms max=363.1ms
  160x encdec n=320 p50=502.1ms p95=654.0ms p99=697.8ms max=797.1ms

[jsx]
  1x encdec n=15 p50=56.6ms p95=76.2ms p99=76.2ms max=83.2ms
  80x encdec n=156 p50=673.3ms p95=764.0ms p99=779.7ms max=800.1ms
  160x encdec n=150 p50=1789.0ms p95=1955.6ms p99=1983.9ms max=1999.8ms

```

> **[Release 2.1.0 · davisp/jiffy](https://github.com/davisp/jiffy/releases/tag/2.1.0)**
>
> What's Changed
> Highlights
> 
> New {max\_depth, N} decode option: decode only the top N levels and keep the rest as pre-encoded JSON that encodes back as is. This could help in routing setups (decode t...

> **[jiffy](https://hex.pm/packages/jiffy/2.1.0)**
>
> JSON Decoder/Encoder.
