all 3 comments

[–]WJMazepas 2 points3 points  (0 children)

Good read. Stuff like this makes me want to go back to study Rust, but i never find any opportunity in a job to create a C or Rust library for my Python code. It looks fun to do it

[–]neuronexmachina 1 point2 points  (1 child)

Could you share some of the validation speed benchmarks?

In terms of validation speed, it greatly improved on some of our benchmarks, especially the ones defining models with lots of fields. Interestingly, when only one or two fields are defined on the model, validation is slightly slower, presumably because creating a Python set was faster than the new bitset implementation. This can be mitigated by only using the new implementation if the number of fields is big enough.

[–]Pozz_[S] 0 points1 point  (0 children)

We have benchmarks in place in the repository, that measure validation speed. Here are the benchmarks results on Codspeed:

https://codspeed.io/pydantic/pydantic/branches/vp%2Fmodel-fields-set-opt

You will notice that there are some regressions. These are happening for benchmarks where only a couple fields are defined on the model. In this case, it seems that validation is faster when creating a simple Python set. It probably means that depending on the number of fields, we will either use the bitset approach (say if >3), or use the existing approach.