-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scrooge-generator - Optimize Scrooge-generated Scala classes from thrift
Problem Scala classes generated by Scrooge in Scala take a long time to compile and generate inefficient bytecode which can hurt likelihood of JVM inlining methods. Solution Remove 'match' which does not translate into a tableswitch in favor of if-else, remove most uses of implicit functions, shadow variables to generate smaller bytecode, eliminate some redundant methods, move common functionality around throwing exceptions into an internal ApplicationExceptions class. Result Compile times for Scrooge-generated Scala times are improved, and smaller bytecode is generated for key methods. JIRA Issues: CSL-8870 Differential Revision: https://phabricator.twitter.biz/D454297
- Loading branch information
1 parent
b72a08c
commit 2189d28
Showing
36 changed files
with
2,500 additions
and
2,828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
scrooge-core/src/main/scala/com/twitter/scrooge/internal/ApplicationExceptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.twitter.scrooge.internal | ||
|
||
import com.twitter.scrooge.ThriftStruct | ||
import org.apache.thrift.TApplicationException | ||
import org.apache.thrift.protocol.TProtocolException | ||
|
||
/** | ||
* Internal helpers for Scrooge classes - should not be called by user code | ||
*/ | ||
object ApplicationExceptions { | ||
|
||
/** | ||
* Given a service name, return a TApplicationException of type MISSING_RESULT | ||
* where the message includes the service name | ||
* @param serviceName | ||
* @return | ||
*/ | ||
def missingResult(serviceName: String): TApplicationException = { | ||
new TApplicationException( | ||
TApplicationException.MISSING_RESULT, | ||
serviceName + " failed: unknown result" | ||
) | ||
} | ||
|
||
/** | ||
* Given a message and the expected and actual type (byte representation), throws a | ||
* TProtocolException - will call String.format on the message with the ttypeToString of the | ||
* expected and actual type bytes as the two args. | ||
* @param message | ||
* @param expectedType | ||
* @param actualType | ||
*/ | ||
@throws[TProtocolException] | ||
def throwWrongFieldTypeException(message: String, expectedType: Byte, actualType: Byte): Unit = { | ||
throw new TProtocolException( | ||
String.format( | ||
message, | ||
ThriftStruct.ttypeToString(expectedType), | ||
ThriftStruct.ttypeToString(actualType))) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.