Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(perf regression): TopicName parsing per publish #2304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SettableApiFuture<AckResponse> getMessageFutureIfExists() {
*/
public PubsubMessageWrapper getMessageWrapper() {
if (this.messageWrapper == null) {
return PubsubMessageWrapper.newBuilder(null, null).build();
return PubsubMessageWrapper.newBuilder(null, (String) null).build();
}
return messageWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public class Publisher implements PublisherInterface {

private static final String OPEN_TELEMETRY_TRACER_NAME = "com.google.cloud.pubsub.v1";

private final String topicName;
private final String topicNameString;
private final TopicName topicName;
private final int topicNameSize;

private final BatchingSettings batchingSettings;
Expand Down Expand Up @@ -146,9 +147,10 @@ public static long getApiMaxRequestBytes() {
}

private Publisher(Builder builder) throws IOException {
topicName = builder.topicName;
topicNameString = builder.topicName;
topicName = TopicName.parse(this.topicNameString);
topicNameSize =
CodedOutputStream.computeStringSize(PublishRequest.TOPIC_FIELD_NUMBER, this.topicName);
CodedOutputStream.computeStringSize(PublishRequest.TOPIC_FIELD_NUMBER, this.topicNameString);

this.batchingSettings = builder.batchingSettings;
FlowControlSettings flowControl = this.batchingSettings.getFlowControlSettings();
Expand Down Expand Up @@ -234,12 +236,12 @@ private Publisher(Builder builder) throws IOException {

/** Topic which the publisher publishes to. */
public TopicName getTopicName() {
return TopicNames.parse(topicName);
return TopicNames.parse(topicNameString);
}

/** Topic which the publisher publishes to. */
public String getTopicNameString() {
return topicName;
return topicNameString;
}

/**
Expand Down Expand Up @@ -490,13 +492,13 @@ private ApiFuture<PublishResponse> publishCall(OutstandingBatch outstandingBatch
pubsubMessagesList.add(messageWrapper.getPubsubMessage());
}

outstandingBatch.publishRpcSpan = tracer.startPublishRpcSpan(topicName, messageWrappers);
outstandingBatch.publishRpcSpan = tracer.startPublishRpcSpan(topicNameString, messageWrappers);

return publisherStub
.publishCallable()
.futureCall(
PublishRequest.newBuilder()
.setTopic(topicName)
.setTopic(topicNameString)
.addAllMessages(pubsubMessagesList)
.build(),
context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ static Builder newBuilder(PubsubMessage message, String topicName) {
return new Builder(message, topicName);
}

static Builder newBuilder(PubsubMessage message, TopicName topicName) {
return new Builder(message, topicName);
}

static Builder newBuilder(
PubsubMessage message, String subscriptionName, String ackId, int deliveryAttempt) {
return new Builder(message, subscriptionName, ackId, deliveryAttempt);
Expand Down Expand Up @@ -402,6 +406,11 @@ public Builder(PubsubMessage message, String topicName) {
}
}

public Builder(PubsubMessage message, TopicName topicName) {
this.message = message;
this.topicName = topicName;
}

public Builder(
PubsubMessage message, String subscriptionName, String ackId, int deliveryAttempt) {
this.message = message;
Expand Down