Skip to content

Commit

Permalink
Improve performance of getObjects() for EntityGroup
Browse files Browse the repository at this point in the history
MethodValueCache's getObjects() implementation was fine for a CacheGroup
because everything was already in memory and fast to fetch. However, an
EntityGroup would end up doing a separate query for every requested entity
and this could be quite slow.

This change simply uses the existing functionality of map() to get all
requested entities in a single query so it is faster for an EntityGroup.
Performance for CacheGroups is not impacted significantly.
  • Loading branch information
Keith R. Gustafson committed Jul 19, 2022
1 parent 97e94fb commit 77d7e0c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions gemini/src/main/java/com/techempower/cache/MethodValueCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package com.techempower.cache;

import gnu.trove.iterator.*;
import gnu.trove.map.*;
import gnu.trove.map.hash.*;
import gnu.trove.set.*;
Expand Down Expand Up @@ -211,16 +210,10 @@ public List<T> getObjects(String methodName, Object value)
{
return new ArrayList<>(0);
}

List<T> values = new ArrayList<>();

for (TLongIterator iterator = ids.iterator(); iterator.hasNext();)
{
long id = iterator.next();
values.add(this.cache.get(this.type, id));
}

return values;

// Provide the list of desired IDs to map() so that, if this is an EntityGroup, we can
// efficiently build all of them from a single query.
return new ArrayList<>(this.cache.map(this.type, ids.toArray()).valueCollection());
}
}
finally
Expand Down

0 comments on commit 77d7e0c

Please sign in to comment.