#5192·diesel

Optimize encoding jsonb literals in the SQLite backend

Author: weiznichCreated Sep 4, 2026Updated Sep 14, 2026
Labelsenhancementhelp wantedsqlite

Each completed nested buffer is copied into its parent, therefore a chain of depth d therefore copies about 1 + 2 + ... + d bytes.

Maybe it could be worth to compute encoded sizes in an iterative first pass, then write every header and value once into the final buffer, using the depth limit as a separate safety bound.

Originally posted by @LucaCappelletti94 in https://github.com/diesel-rs/diesel/pull/5172#discussion_r3905594505

We would like to optimize the code in https://github.com/diesel-rs/diesel/blob/12189c398a98e3c50a4260368890449595e91ad8/diesel/src/sqlite/types/json.rs#L470-L524 to iterativly calculate the encoded size of each nested array/object first and then write the encoded result in one go to the output buffer.