[wildfly-dev] Perf tip for folks writing management code

Brian Stansberry brian.stansberry at redhat.com
Wed Aug 26 18:53:34 EDT 2015


On 8/26/15 2:19 PM, Brian Stansberry wrote:
> If you're writing code that manipulates potentially large chunks of the
> management model, be cautious of the following:
>
> 1) org.jboss.as.controller.Registry.Tools.readModel(final Resource resource)
>
> This makes a deep clone of all the DMR model nodes in the given resource
> tree. That may be a good thing, but is expensive with large trees, so be
> aware.
>
> 2) org.jboss.dmr.ModelNode.asPropertyList()
>
> For each Property in the returned list, the 'value' member is a deep
> clone of the corresponding element in the original model node. So, again
> expensive with large trees, so be aware.
>
> You can replace this:
>
> for (Property prop : node.asPropertyList() {
>      String name = prop.getName();
>      ModelNode value = prop.getValue();
>      ... do something with name and value
> }
>
> with
>
> for (String name : node.keys()) {
>       ModelNode value = node.get(name);
>       ... do something with name and value
> }

Note: this is not the right thing to do if node.getType() == 
ModelType.LIST with each list element a ModelType.PROPERTY. The keys() 
and get(String) methods are not supported for nodes of that type.

These are unusual in the WildFly model though, other than the "address" 
node of an operation object. And that node is usually is handled by 
kernel code anyway.

>
> I'll fix a few high impact cases of this usage.
>
> Please resist the urge to send in lots of refactoring PRs until WF 10 is
> done. ;)
>


-- 
Brian Stansberry
Senior Principal Software Engineer
JBoss by Red Hat


More information about the wildfly-dev mailing list