thriftrw / thriftrw-python

A Thrift encoding library for Python
MIT License
36 stars 10 forks source link

Avoid multiple validation #71

Closed abhinav closed 7 years ago

abhinav commented 9 years ago

Currently we end up validating structs multiple times. All the fields of a struct are validated upon construction. But if the struct is then used as an argument to another struct, all fields on that new struct will be validated -- including the already-validated struct. This can be really expensive when a large number of objects is involved, and I wouldn't be surprised if this is significantly hurting our deserialization performance.

foos = [Foo(x) for i in xrange(1000)]  # all objects are validated upon construction
bar = Bar(foos=foos)  # here they're validated again

One possible solution is to track this in a _validated attribute. It'll have to be set to False when attributes on the object are changed manually using obj.attr = foo.

clin88 commented 7 years ago

Resolved with f719d7b1524d31545082abb83789c4265fa6eab2