Skip to content
Snippets Groups Projects
  • Vladislav Shpilevoy's avatar
    3298f129
    json: use cord_ibuf for encoding and decoding · 3298f129
    Vladislav Shpilevoy authored
    Lua json module used to have a global buffer for all encodings. It
    was reused by each next encode().
    
    This was not correct, because during encode() might happen a GC
    step, which might call encode() again and spoil the global buffer.
    
    The same problem was already fixed for the global static buffer in
    scope of #5632. Similarly to that time, the patch makes Lua json
    module use cord_ibuf to prevent "concurrent" usage of the buffer
    data. The global buffer is deleted.
    
    According to a few microbenchmarks it didn't affect the perf
    anyhow.
    
    Core part of the patch is strbuf changes. Firstly, its destruction
    is now optional, cord_ibuf can free itself on a next yield.
    Secondly, its reallocation algorithm is kept intact - ibuf is used
    as an allocator, not as the buffer itself. This is done so as not
    to be too intrusive in the third party module which might need an
    upgrade to the upstream in the future.
    
    Closes #6050
    3298f129
    History
    json: use cord_ibuf for encoding and decoding
    Vladislav Shpilevoy authored
    Lua json module used to have a global buffer for all encodings. It
    was reused by each next encode().
    
    This was not correct, because during encode() might happen a GC
    step, which might call encode() again and spoil the global buffer.
    
    The same problem was already fixed for the global static buffer in
    scope of #5632. Similarly to that time, the patch makes Lua json
    module use cord_ibuf to prevent "concurrent" usage of the buffer
    data. The global buffer is deleted.
    
    According to a few microbenchmarks it didn't affect the perf
    anyhow.
    
    Core part of the patch is strbuf changes. Firstly, its destruction
    is now optional, cord_ibuf can free itself on a next yield.
    Secondly, its reallocation algorithm is kept intact - ibuf is used
    as an allocator, not as the buffer itself. This is done so as not
    to be too intrusive in the third party module which might need an
    upgrade to the upstream in the future.
    
    Closes #6050