[jboss-user] [JBoss Microcontainer Development] New message: "Re: Profiling the dependency project"
Kabir Khan
do-not-reply at jboss.com
Thu Feb 11 06:00:22 EST 2010
User development,
A new message was posted in the thread "Profiling the dependency project":
http://community.jboss.org/message/525701#525701
Author : Kabir Khan
Profile : http://community.jboss.org/people/kabir.khan@jboss.com
Message:
--------------------------------------------------------------
I tried indexing the dependencies by state since a lot of time is spent iterating over the dependencies to determine the unresolved dependencies, however this had an adverse effect, making it a bit slower
> $svn diff
> Index: dependency/src/main/java/org/jboss/dependency/plugins/AbstractDependencyInfo.java
> ===================================================================
> --- dependency/src/main/java/org/jboss/dependency/plugins/AbstractDependencyInfo.java (revision 100812)
> +++ dependency/src/main/java/org/jboss/dependency/plugins/AbstractDependencyInfo.java (working copy)
> @@ -24,7 +24,9 @@
> import java.util.Collections;
> import java.util.HashSet;
> import java.util.List;
> +import java.util.Map;
> import java.util.Set;
> +import java.util.concurrent.ConcurrentHashMap;
> import java.util.concurrent.CopyOnWriteArrayList;
> import java.util.concurrent.CopyOnWriteArraySet;
>
> @@ -64,6 +66,10 @@
> /** Whether this is an autowire candidate */
> private boolean autowireCandidate = true;
>
> + private Map<ControllerState, Set<DependencyItem>> iDependOnByState = new ConcurrentHashMap<ControllerState, Set<DependencyItem>>(5, .75f, 1);
> +
> +// private static final ControllerState NULL_CONTROLLER_STATE = ControllerState.newState("Null_AbstractDependencyInfo");
> +
> /**
> * Create an abstract dependency info
> */
> @@ -90,12 +96,34 @@
> public void addIDependOn(DependencyItem dependency)
> {
> iDependOn.add(dependency);
> +
> + if (dependency.getWhenRequired() == null)
> + return;
> +
> + Set<DependencyItem> dependOnForState = iDependOnByState.get(dependency.getWhenRequired());
> + if (dependOnForState == null)
> + {
> + dependOnForState = new CopyOnWriteArraySet<DependencyItem>();
> + Set<DependencyItem> old = iDependOnByState.put(dependency.getWhenRequired(), dependOnForState);
> + if (old != null)
> + dependOnForState = old;
> + }
> + dependOnForState.add(dependency);
> +
> flushJBossObjectCache();
> }
>
> public void removeIDependOn(DependencyItem dependency)
> {
> iDependOn.remove(dependency);
> +
> + if (dependency.getWhenRequired() == null)
> + return;
> +
> + Set<DependencyItem> dependOnForState = iDependOnByState.get(dependency.getWhenRequired());
> + if (dependOnForState != null)
> + dependOnForState.remove(dependency);
> +
> flushJBossObjectCache();
> }
>
> @@ -147,24 +175,61 @@
> if (iDependOn.isEmpty())
> return Collections.emptySet();
>
> + //Old way
> +// Set<DependencyItem> result = null;
> +// for (DependencyItem item : iDependOn)
> +// {
> +// if (state == null || state.equals(item.getWhenRequired()))
> +// {
> +// if (item.isResolved() == false)
> +// {
> +// if (result == null)
> +// result = new HashSet<DependencyItem>();
> +// result.add(item);
> +// }
> +// }
> +// }
> +
> + //New way
> Set<DependencyItem> result = null;
> - for (DependencyItem item : iDependOn)
> + if (state != null)
> {
> - if (state == null || state.equals(item.getWhenRequired()))
> + Set<DependencyItem> dependenciesForState = iDependOnByState.get(state);
> + if (dependenciesForState != null)
> {
> - if (item.isResolved() == false)
> + for (DependencyItem item : dependenciesForState)
> {
> - if (result == null)
> - result = new HashSet<DependencyItem>();
> - result.add(item);
> + if (item.isResolved() == false)
> + {
> + if (result == null)
> + result = new HashSet<DependencyItem>();
> + result.add(item);
> + }
> }
> }
> }
> + else
> + {
> + for (DependencyItem item : iDependOn)
> + {
> + if (state == null)
> + {
> + if (item.isResolved() == false)
> + {
> + if (result == null)
> + result = new HashSet<DependencyItem>();
> + result.add(item);
> + }
> + }
> + }
> + }
> +
> +
> if (result == null)
> return Collections.emptySet();
> return result;
> }
> -
> +
> public <T> void addInstallItem(CallbackItem<T> callbackItem)
> {
> installCallbacks.add(callbackItem);
>
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/525701#525701
More information about the jboss-user
mailing list