Skip to content

Commit

Permalink
Remove allocation of capturing lambdas in TransportBulkAction (#104841)
Browse files Browse the repository at this point in the history
These two lambdas combined account for more than 1.5% of all allocations during indexing in the http_logs
benchmark. We would expect to repeatedly see the same index over and over in a bulk request, so the small
saving for hashing + lookup from computeIfAbsent is effectively irrelevant while the allocations incur
a measurable cost.
  • Loading branch information
original-brownbear committed Jan 29, 2024
1 parent f6e9ada commit 99e72b0
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,12 @@ private static class ConcreteIndices {

IndexAbstraction resolveIfAbsent(DocWriteRequest<?> request) {
try {
return indexAbstractions.computeIfAbsent(
request.index(),
key -> indexNameExpressionResolver.resolveWriteIndexAbstraction(state, request)
);
IndexAbstraction indexAbstraction = indexAbstractions.get(request.index());
if (indexAbstraction == null) {
indexAbstraction = indexNameExpressionResolver.resolveWriteIndexAbstraction(state, request);
indexAbstractions.put(request.index(), indexAbstraction);
}
return indexAbstraction;
} catch (IndexNotFoundException e) {
if (e.getMetadataKeys().contains(EXCLUDED_DATA_STREAMS_KEY)) {
throw new IllegalArgumentException("only write ops with an op_type of create are allowed in data streams", e);
Expand All @@ -937,7 +939,12 @@ IndexAbstraction resolveIfAbsent(DocWriteRequest<?> request) {
}

IndexRouting routing(Index index) {
return routings.computeIfAbsent(index, idx -> IndexRouting.fromIndexMetadata(state.metadata().getIndexSafe(idx)));
IndexRouting routing = routings.get(index);
if (routing == null) {
routing = IndexRouting.fromIndexMetadata(state.metadata().getIndexSafe(index));
routings.put(index, routing);
}
return routing;
}
}

Expand Down

0 comments on commit 99e72b0

Please sign in to comment.