Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upConsider orjson support #271
Comments
|
|
|
Hm I think I was hitting https://github.com/hynek/structlog/blob/master/src/structlog/_base.py#L174? |
|
Returning strings is just a shortcut for |
|
Ah I see, so there's nothing stopping me from playing with this. Thanks! |
|
So do I understand this correctly that to make it work at the moment without decoding the bytes to a string (and this indeed loses some performance according to a small benchmark I did) I need to do something like the following:
and for serialization use something like
to avoid exceptions from the |
|
You tell us, if you tested/benchmarked it. :D Do you have any numbers on vs stdlib json and simplejson? Please use https://pypi.org/project/pyperf/ We might fold it into the docs if it's significant enough. |
|
I only did a basic benchmark of There are quite a few results on the orjson page though. I am not really sure if or how it would be possible to benchmark the integration of |
|
Yeah I know orjson is very fast, the question is if it makes any difference in the context of small dicts that go thru I/O. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Hi,
orjson is a new contender in the space of optimized json libraries, claiming to be the fastest. I'm wondering if it can be made to work with structlog.
orjson only outputs bytes (utf8 encoded strings). Decoding this output back into a string would probably lose some of the advantages of using orjson in the first place, so I'm interested whether we can figure out a way to integrate it without decoding.
I'm mostly interested in writing to stdout/stderr in a server environment, where these optimizations are most useful. A custom logger class could write the bytes directly to stdout using
sys.stdout.buffer, I guess.structlogdoesn't like the final output of the processor chain to be bytes, right?