I have ended up in a situation where using projection with ndb.get_multi()
did result in performance improvements. I have a large entity class with ~25 properties, some of which are even repeated. I need to get_by_id about 10 of these objects for serving each web page in my app, but I only need 4 properties per object. If I implement this using plain ndb.get_multi()
, then around half the frontend CPU time ends up being spent in an NDB API method named Model._from_pb
, i.e. deserializing the objects that were read from the database. This looks like something that might be improved with projection, and indeed, in my case using projection the below way have cut the overall response time by half:
Product.query(Product.key.IN(keys_to_get)).fetch(projection=list_of_columns)
Where Product
is the name of my entity class. Of course in this case a new index is needed for the query.