Skip to content

Commit

Permalink
Lite: Remove intermediary dynamicMethod function trampolines
Browse files Browse the repository at this point in the history
These hurt performance by adding extra instructions and branches.

PiperOrigin-RevId: 684621860
  • Loading branch information
mhansen authored and copybara-github committed Oct 10, 2024
1 parent c828b84 commit 25724ab
Showing 1 changed file with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,24 @@ boolean hashCodeIsNotMemoized() {
@Override
@SuppressWarnings("unchecked") // Guaranteed by runtime.
public final Parser<MessageType> getParserForType() {
return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER);
return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER, null, null);
}

@Override
@SuppressWarnings("unchecked") // Guaranteed by runtime.
public final MessageType getDefaultInstanceForType() {
return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE);
return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE, null, null);
}

@Override
@SuppressWarnings("unchecked") // Guaranteed by runtime.
public final BuilderType newBuilderForType() {
return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER, null, null);
}

@SuppressWarnings("unchecked") // Guaranteed by runtime.
MessageType newMutableInstance() {
return (MessageType) dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
return (MessageType) dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE, null, null);
}

/**
Expand Down Expand Up @@ -202,11 +203,12 @@ protected void makeImmutable() {
markImmutable();
}

@SuppressWarnings("unchecked") // Guaranteed by runtime.
protected final <
MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>>
BuilderType createBuilder() {
return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER, null, null);
}

protected final <
Expand All @@ -224,7 +226,7 @@ public final boolean isInitialized() {
@Override
@SuppressWarnings("unchecked")
public final BuilderType toBuilder() {
BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER, null, null);
return builder.mergeFrom((MessageType) this);
}

Expand Down Expand Up @@ -275,19 +277,6 @@ protected abstract Object dynamicMethod(
Object arg0,
Object arg1);

/** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */
@CanIgnoreReturnValue
protected Object dynamicMethod(
MethodToInvoke method,
Object arg0) {
return dynamicMethod(method, arg0, null);
}

/** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */
protected Object dynamicMethod(MethodToInvoke method) {
return dynamicMethod(method, null, null);
}

void clearMemoizedSerializedSize() {
setMemoizedSerializedSize(UNINITIALIZED_SERIALIZED_SIZE);
}
Expand Down Expand Up @@ -355,7 +344,7 @@ private int computeSerializedSize(

/** Constructs a {@link MessageInfo} for this message type. */
Object buildMessageInfo() throws Exception {
return dynamicMethod(MethodToInvoke.BUILD_MESSAGE_INFO);
return dynamicMethod(MethodToInvoke.BUILD_MESSAGE_INFO, null, null);
}

private static Map<Class<?>, GeneratedMessageLite<?, ?>> defaultInstanceMap =
Expand Down Expand Up @@ -1474,7 +1463,7 @@ GeneratedExtension<MessageType, T> checkIsLite(ExtensionLite<MessageType, T> ext
protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitialized(
T message, boolean shouldMemoize) {
byte memoizedIsInitialized =
(Byte) message.dynamicMethod(MethodToInvoke.GET_MEMOIZED_IS_INITIALIZED);
(Byte) message.dynamicMethod(MethodToInvoke.GET_MEMOIZED_IS_INITIALIZED, null, null);
if (memoizedIsInitialized == 1) {
return true;
}
Expand All @@ -1486,7 +1475,7 @@ GeneratedExtension<MessageType, T> checkIsLite(ExtensionLite<MessageType, T> ext
// TODO: remove the unused variable
Object unused =
message.dynamicMethod(
MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null);
MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null, null);
}
return isInitialized;
}
Expand Down

0 comments on commit 25724ab

Please sign in to comment.