ijl / orjson

Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Apache License 2.0
6.23k stars 215 forks source link

In-palce `loads()` #513

Closed devova closed 2 months ago

devova commented 2 months ago

I really would like an option of not generating a new PyObject every time loads() is called and rather update existing one.

It would reduce amount of memory the interpreter allocate. This use case would be very handy during stream processing, when a message get processed and you for sure don't need it anymore. Of course garbage collector will take care of it implicitly, but having control of it is a great option, specially when you are dealing with streams with high frequencies, like > 1KHz, As result instead of having ramp-up memory it would be just a linear.

As proposed API, it might look like:

  1.  orjson.loads(..., singleton_name="my stream identifier")
  2.  my_stream = orjson.Singelton()
     my_stream.loads()