-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider 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. |
I believe https://www.structlog.org/en/latest/api.html#structlog.BytesLogger does what you asked for. LMK if not. I'll try to add basic log levels before releasing too. |
Excellent, thanks! Will give this a try. |
1baf23f was the missing piece that allows processors to return bytes. |
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.structlog
doesn't like the final output of the processor chain to be bytes, right?The text was updated successfully, but these errors were encountered: