ArduinoJson 6.7.0-beta reverts the changes introduced in the previous release. It reduced the code size and memory usage, and it improves the performance.

Going back to a monotonic allocator

In ArduinoJson 6.6.0, I replaced the monotonic allocator with a full-blown allocator and an automatic compaction mechanism. It meant that you could replace and remove values repeatedly without worrying about the capacity of the JsonDocument.

Inevitably, this feature caused a significant augmentation of the code size and memory usage. Unfortunately, you had to pay this price even if you don’t replace and remove values. In other words, the main use-cases (serializing and deserializing JSON documents) were penalized in favor of a rare use-case (editing a JSON document).

The size increase was acceptable for modern microcontrollers, like the ESP8266, but was hazardous for older ones, like the ATmega328 in the Arduino UNO board.

The difference with ArduinoJson 5 was so significant that I would need to recommend version 5 for some boards and version 6 for others. Not only, it would force me to maintain two separate branches, but it would also force you to rewrite your code whenever you decide to replace your microcontroller.

For these reasons, I decided to revert the changes introduced in version 6.6.0 and to restore the original monotonic allocator that made the success of the library so far. It was not an easy decision because I invested a lot of time and energy into this feature, but I know it’s the right choice.

By restoring the original allocator, the size of ArduinoJson 6 is comparable to version 5, and the memory consumption is significantly lower. Now, every user of version 5 can safely upgrade to version 6 without upgrading the microcontroller.

Evolution of code size

The following graph shows the size of the examples JsonParserExample.ino and JsonGeneratorExample.ino on ATmega328.

Evolution of the code size of ArduinoJson on ATmega328

Here is the same graph for ESP8266:

Evolution of the code size of ArduinoJson on ESP8266

Evolution of memory usage

The following graph shows the size of the JsonDocument (or JsonBuffer) in these examples:

Evolution of the memory usage of ArduinoJson on ATmega328

Here is the same graph for ESP8266:

Evolution of the memory usage of ArduinoJson on ESP8266

Fixed capacity for DynamicJsonDocument

Since we’re very close to the end of the beta stage, I included the last significant change in the library. Starting with ArduinoJson 6.7.0, the DynamicJsonDocument has a fixed capacity, just like the StaticJsonDocument.

Historically, DynamicJsonDocument was able to grow as needed, allocating new blocks of memory as soon as the capacity is reached. However, this feature produced a lot of heap fragmentation and was hitting performance.

I always thought that the elastic capacity caused more harm than good, so I’m glad to finally have the opportunity to remove this feature. It’s possible that I’ll release a version of ArduinoJson 5 in which the capacity of the DynamicJsonBuffer is fixed too.

Stay informed!

...or subscribe to the RSS feed