Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reduce DomainClass autowiring call overhead (it showed up in top bloc…

…king methods while profiling)
  • Loading branch information...
commit 452a12d63d3a02a29b6df0a85df8a736778b9f34 1 parent d763666
Lari Hotari lhotari authored
9 grails-bootstrap/src/main/groovy/grails/util/Environment.java
View
@@ -93,6 +93,7 @@
TEST_ENVIRONMENT_SHORT_NAME, Environment.TEST.getName());
private static Holder<Environment> cachedCurrentEnvironment = new Holder<Environment>("Environment");
private static final boolean cachedHasGrailsHome = System.getProperty("grails.home") != null;
+ private static boolean initializingState = false;
private String name;
Environment() {
@@ -400,8 +401,14 @@ public static boolean isInteractiveMode() {
* @return Whether interactive mode is enabled
*/
public static boolean isInitializing() {
- return Boolean.getBoolean(INITIALIZING);
+ return initializingState;
}
+
+ public static void setInitializing(boolean initializing) {
+ initializingState=initializing;
+ System.setProperty(INITIALIZING, String.valueOf(initializing));
+ }
+
/**
* @return true if the reloading agent is active
*/
4 grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/spring/GrailsRuntimeConfigurator.java
View
@@ -166,9 +166,9 @@ public WebApplicationContext configure(ServletContext context, boolean loadExter
application.setMainContext(springConfig.getUnrefreshedApplicationContext());
- System.setProperty(Environment.INITIALIZING, "true");
+ Environment.setInitializing(true);
ctx = (WebApplicationContext) springConfig.getApplicationContext();
- System.setProperty(Environment.INITIALIZING, "");
+ Environment.setInitializing(false);
pluginManager.setApplicationContext(ctx);
pluginManager.doDynamicMethods();
3  ...ore/src/main/groovy/org/codehaus/groovy/grails/commons/spring/ReloadAwareAutowireCapableBeanFactory.java
View
@@ -182,6 +182,9 @@ protected boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) {
@Override
public void autowireBeanProperties(Object existingBean, int autowireMode,
boolean dependencyCheck) throws BeansException {
+ if(Environment.isInitializing()) {
+ return;
+ }
if(autowireMode == AUTOWIRE_BY_NAME) {
if(DISABLE_AUTOWIRE_BY_NAME_OPTIMIZATIONS || dependencyCheck || existingBean instanceof Aware) {
super.autowireBeanProperties(existingBean, autowireMode, dependencyCheck);
6 ...ls-plugin-domain-class/src/main/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy
View
@@ -203,9 +203,11 @@ class DomainClassGrailsPlugin {
return gormValidationApi
}
}
+
+ AutowireCapableBeanFactory autowireCapableBeanFactory=ctx.autowireCapableBeanFactory
+ int byName=AutowireCapableBeanFactory.AUTOWIRE_BY_NAME
metaClass.static.autowireDomain = { instance ->
- if(!Environment.isInitializing())
- ctx.autowireCapableBeanFactory.autowireBeanProperties(instance,AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false)
+ autowireCapableBeanFactory.autowireBeanProperties(instance, byName, false)
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.