Avoid usage of dynamic vars when reading and writing json

Description

As pr DJSON-31, benchmarks show that the cost of setting up the bindings for the dynamic vars is high, especially when working with small json payloads.

Approach 1

Passing an options map instead of using dynamic vars.

Patch

0001-DJSON-32-Use-options-map-instead-of-dynamic-vars.patch

Read bench

10b

100b

1k

10k

100k

694.460026 ns

3.082386 µs

20.594645 µs

233.378285 µs

2.241845 ms

Write bench

10b

100b

1k

10k

100k

879.187915 ns

5.298470 µs

33.521159 µs

453.793565 µs

4.151918 ms

Although this speeds up quite a bit compared to using the dynamic vars, the creation of the options-map incurs a penalty, as seen from the benchmarks in where parameter passing was used.

For reading, I’d suggest passing them as params as it’s only three of them. For writing, the code is somewhat more involved, so it might make sense to pass them as a map.

It might also be that there is a faster way to create the options maps.

Environment

None

Activity

Show:
Alex Miller
March 12, 2021, 4:10 PM

Applied

Erik Assum
March 12, 2021, 3:47 PM

Updated patch with benchmarking code and data

0003-DJSON-32-Use-options-maps-instead-of-dynamic-vars.patch

Erik Assum
March 12, 2021, 3:11 PM

Done in 0002-DJSON-32-Use-options-maps-instead-of-dynamic-vars.patch

Alex Miller
March 12, 2021, 2:54 PM

Can you switch from using hash-map when constructing the option maps to array-map? If it's not already faster now, it likely will be in 1.11.

I think we should use options map for both reading and writing - that's going to evolve better and there is still more room to reduce the overhead in option map construction but we can defer that to future.

Fixed

Assignee

Alex Miller

Reporter

Erik Assum