Skip to content

Commit

Permalink
perf(redis): Replace String.format with String.join (#3836)
Browse files Browse the repository at this point in the history
When caching large Kubernetes clusters, ~25% of allocated objects per
caching cycle are from calling String.format on cache keys.

String.format is significantly more expensive than String.join as
it parses the input as a regular expression. In this case, we can
replace the calls to .format() with calls to .join() while keeping
exactly the same functionality.
  • Loading branch information
ezimanyi committed Jul 2, 2019
1 parent 9b3fef6 commit f8b434d
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,23 @@ protected boolean isHashingDisabled(String type) {
}

protected String attributesId(String type, String id) {
return String.format("%s:%s:attributes:%s", prefix, type, id);
return String.join(":", prefix, type, "attributes", id);
}

protected String relationshipId(String type, String id, String relationship) {
return String.format("%s:%s:relationships:%s:%s", prefix, type, id, relationship);
return String.join(":", prefix, type, "relationships", id, relationship);
}

private String hashesDisabled(String type) {
return String.format("%s:%s:hashes.disabled", prefix, type);
return String.join(":", prefix, type, "hashes.disabled");
}

protected String allRelationshipsId(String type) {
return String.format("%s:%s:relationships", prefix, type);
return String.join(":", prefix, type, "relationships");
}

protected String allOfTypeId(String type) {
return String.format("%s:%s:members", prefix, type);
return String.join(":", prefix, type, "members");
}

protected TypeReference getRelationshipsTypeReference() {
Expand Down

0 comments on commit f8b434d

Please sign in to comment.