Files
json/include/nlohmann/detail
Niels Lohmann eb251df17c Size and write BSON arrays of numbers without a frame on the stack
Every array nested in a BSON document pushed a frame of about 100 bytes on a
vector, replaced the current one by moving, and popped it again, once for the
size pass and once for the write pass. For the many small arrays of numbers
(coordinates, vectors) that was more than the work on their entries.

An array whose elements are all booleans, numbers, or null is now sized by a
loop of its own, and written in the loop for fixed-size entries on a frame
that is not pushed. The entries of other arrays go to the fixed-size loop only
when the element is such a value, which also saves the call for an array of
strings. An array with an integer that does not fit 64 bits (possible with
number types wider than that) is left to the generic path, which throws.

Instructions per call (Linux, GCC 13, thousands), to_bson: canada 46833 -> 30575, 20000 integers 2680 -> 1839, 20000 floats 3050 -> 2209, citm_catalog 14536 -> 13235, 20000 small objects 33294 -> 31954.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-22 09:29:04 +02:00
..