I just profiled some code where I increment some frequency counters with the following code:
Datastore ds = ...
final Query<Unit> query = ds.createQuery(Unit.class);
query.field("text").equal(text);
query.field("langCode").equal(lang.getCode());
UpdateOperations ops = ds.createUpdateOperations(Unit.class);
ops.inc("frequency", value);
ds.update(query, ops, false);
Creating a query takes almost 50% of the execution time, and I would like to somehow reuse it. Is it safe to store objects queryand opsin ThreadLocal and just call query.field("text").equal(text)again to replace the "text" field? It also appears that validation takes up about 30% of the total time.
source
share