guice optimization

only under debug logging use the source provider to find the line number through stack trace elements, otherwise, its very expensive
This commit is contained in:
Shay Banon 2013-07-05 22:47:27 -07:00
parent b9a2fbd874
commit f4d1895399
1 changed files with 14 additions and 3 deletions

View File

@ -19,12 +19,15 @@ package org.elasticsearch.common.inject.spi;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.elasticsearch.bootstrap.Bootstrap;
import org.elasticsearch.common.inject.*; import org.elasticsearch.common.inject.*;
import org.elasticsearch.common.inject.binder.AnnotatedBindingBuilder; import org.elasticsearch.common.inject.binder.AnnotatedBindingBuilder;
import org.elasticsearch.common.inject.binder.AnnotatedConstantBindingBuilder; import org.elasticsearch.common.inject.binder.AnnotatedConstantBindingBuilder;
import org.elasticsearch.common.inject.binder.AnnotatedElementBuilder; import org.elasticsearch.common.inject.binder.AnnotatedElementBuilder;
import org.elasticsearch.common.inject.internal.*; import org.elasticsearch.common.inject.internal.*;
import org.elasticsearch.common.inject.matcher.Matcher; import org.elasticsearch.common.inject.matcher.Matcher;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.*; import java.util.*;
@ -309,10 +312,18 @@ public final class Elements {
return builder; return builder;
} }
private static ESLogger logger = Loggers.getLogger(Bootstrap.class);
protected Object getSource() { protected Object getSource() {
return sourceProvider != null Object ret;
if (logger.isDebugEnabled()) {
ret = sourceProvider != null
? sourceProvider.get() ? sourceProvider.get()
: source; : source;
} else {
ret = source;
}
return ret == null ? "_unknown_" : ret;
} }
@Override @Override