Make command line option parsing ~6500% faster
Guice does not like to pass an Injector as part of an @Assisted invocation of an object. More recent versions of Guice are logging a warning advising a performance boost of ~6500% is possible if the class stops accepting Injector in the constructor and instead uses a more concrete type. In this case Guice was very correct about the code being slow. Every option declared required a linear scan through the entire Injector stack looking for any candidate binding that might match the OptionHandlerFactory signature. This scan ran on each request, which is incredibly slow. Build the map once in the injector and retain as a singleton. Change-Id: Ib620e7bf1e24241bd373d2cb55c89c3fe3284645
This commit is contained in:
@@ -18,8 +18,6 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.config.FactoryModule;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.args4j.AccountGroupIdHandler;
|
||||
import com.google.gerrit.server.args4j.AccountGroupUUIDHandler;
|
||||
import com.google.gerrit.server.args4j.AccountIdHandler;
|
||||
@@ -28,11 +26,12 @@ import com.google.gerrit.server.args4j.ObjectIdHandler;
|
||||
import com.google.gerrit.server.args4j.PatchSetIdHandler;
|
||||
import com.google.gerrit.server.args4j.ProjectControlHandler;
|
||||
import com.google.gerrit.server.args4j.SocketAddressHandler;
|
||||
import com.google.gerrit.server.config.FactoryModule;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.util.cli.CmdLineParser;
|
||||
import com.google.gerrit.util.cli.OptionHandlerUtil;
|
||||
|
||||
import com.google.gerrit.util.cli.OptionHandlers;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
@@ -44,6 +43,7 @@ public class CmdLineParserModule extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
factory(CmdLineParser.Factory.class);
|
||||
bind(OptionHandlers.class);
|
||||
|
||||
registerOptionHandler(Account.Id.class, AccountIdHandler.class);
|
||||
registerOptionHandler(AccountGroup.Id.class, AccountGroupIdHandler.class);
|
||||
|
||||
Reference in New Issue
Block a user