Orjson in Pydantic V2 #6388
Replies: 8 comments 23 replies
-
No, using |
Beta Was this translation helpful? Give feedback.
-
According to the Migration Guide:
however, no alternative is suggested, and no explanation of why, or to what effect. It seems like a very strange decision, and one that probably puts people off from upgrading from V1. |
Beta Was this translation helpful? Give feedback.
-
it doesn't matter to everyone what it is written on, even rust, even c++, as a library user in python, I want speed. Your rust is the same speed as Python json. What is the meaning of it for me as a user? besides the fact that it is written in RUST))kkak it's cool RUST - no) |
Beta Was this translation helpful? Give feedback.
-
Any highly loaded professional project removes the pydantic as it is slow. What is not clear? |
Beta Was this translation helpful? Give feedback.
-
@samuelcolvin Python's built-in Approach 1: 15 seconds (combined total over 210 server responses) result = MyModel[MyProps](**json.loads(body_bytes)) Approach 2: 22 seconds (combined total over the same 210 server responses) result = MyModel[MyProps].model_validate_json(body_bytes) Both results are better than V1, however, I'm struggling to see the promised speed advantage of |
Beta Was this translation helpful? Give feedback.
-
JOOI - what's the latest benchmarking here? Is the native pydantic (de)serialization significantly slower than orjson? |
Beta Was this translation helpful? Give feedback.
-
There is another point, which is kind of discussed here, but not directly - custom encoders. I have a project, which for the past decade used vanilla Here are several examples of the encoder rules:
There are a couple of more rules, but you get the idea. I understand, that there is now a concept of Serialization, but that isn't quite the same as before, when I could re-use the well established serialization rules. I guess for now I will have to use I don't know if I have any specific questions right now, but I just wanted to point out that there is more to the discussion, then performance considerations. |
Beta Was this translation helpful? Give feedback.
-
Could you please provide the full code snippet used to analyze the differing performance? I'm doing a presentation on performance with pydantic, and want to collect the latest metrics for tests like yours :). |
Beta Was this translation helpful? Give feedback.
-
In Pydantic V1, I use
orjson
for myjson_dumps
andjson_loads
:I am having a little trouble figuring out how to do this in Pydantic V2, or if this is even necessary. With pydantic-core rewritten in Rust and the performance improvements along with it, is using orjson even necessary? Or would the configuration look more like implementing a
SchemaSerializer
? Thinking something like this in V2, but wondering what I would give up in Pydantic V2 for this somewhat-ham-fisted approach:Beta Was this translation helpful? Give feedback.
All reactions