Pickling can be expensive

When trying to serialize python data, often the first thing we look at is pickle. Well, sometimes pickle can be very expensive!

Here Post is an elixir class, which means it's an object mapped to a relational database, and comparing its properties to something is pretty much a piece of a SQL WHERE statement.

>>> print Post.important==True
posts.important = ?

What happens when we pickle it?

>>> print len(pickle.dumps(Post.important==True))
27287
>>> print pickle.loads(s)
posts.important = :important_1

Yikes. What's a better solution?

>>> print eval('Post.important==True')
posts.important = ?

As long as we are sure no weird data will get into the eval...

Comments

Comments powered by Disqus