Title: XML Marshalling performance improvement

Hi,

I've been playing with Castor for a few days (excellent product) and I'm happy with the performance of the unmarshalling, however I was surprised with the performance of the marshalling, I expected it to be much faster.

First off, sorry for the long email, it's not as bad as it looks.  I know it's frustrating when people just complain that something is too slow, so I took a quick look to see if there was anything obvious that could give a quick gain.  With a few minor changes I was able to achieve a consistent 10% improvement in marshalling (I know it doesn't sound like much, but to those of us who live and die for performance it's significant).  I'd like to see if these changes can be integrated into the Castor source tree, or if I'm just out to lunch.

Change details:

-Using Castor 0.9.5.3 source.
-Used source generator on the WSRP Schema (http://www.oasis-open.org/committees/wsrp/specifications/version1/wsrp_v1_types.xsdGenerated), using the "type" method.

-In Marshaller.java in the lines:

        //-- obtain the class descriptor
        XMLClassDescriptor classDesc = null;
        boolean saveType = false; /* flag for xsi:type */
        if (_class == descriptor.getFieldType())
            classDesc = (XMLClassDescriptor)descriptor.getClassDescriptor();

        if (classDesc == null) {
                <snip_do_lots_of_work/>

-I noticed that statement "if (classDesc == null)" is always true, meaning the "<snip_do_lots_of_work/>" always gets executed.

-To make this statement false I edited the generated descriptor files and added the line desc.setClassDescriptor( xxx ) for each field descriptor that had a class descriptor, for example in the generate code below I added the "marked section"

        desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(com.cognos.cps.services.wsrp.types.Extension.class, "_extensionsList", "extensions", org.exolab.castor.xml.NodeType.Element);

        handler = (new org.exolab.castor.xml.XMLFieldHandler() {
            public java.lang.Object getValue( java.lang.Object object )
                throws IllegalStateException
            {
                ServiceDescription target = (ServiceDescription) object;
                return target.getExtensions();
            }
            public void setValue( java.lang.Object object, java.lang.Object value)
                throws IllegalStateException, IllegalArgumentException
            {
                try {
                    ServiceDescription target = (ServiceDescription) object;
                    target.addExtensions( (com.cognos.cps.services.wsrp.types.Extension) value);
                }
                catch (java.lang.Exception ex) {
                    throw new IllegalStateException(ex.toString());
                }
            }
            public java.lang.Object newInstance( java.lang.Object parent ) {
                return new com.cognos.cps.services.wsrp.types.Extension();
            }
        } );
        desc.setHandler(handler);
        desc.setNameSpaceURI("urn:oasis:names:tc:wsrp:v1:types");
        desc.setMultivalued(true);
          desc.setClassDescriptor( new ExtensionDescriptor() );  // Added by Derek
        addFieldDescriptor(desc);


For strings I added "setClassDescriptor( new StringClassDescriptor())  This was a very generic change, so my question is can this be integrated into the SourceGenerator?

Here's my test driver, for those that are interested (if you want my modified generated source let me know).

<<TestCastorPerformance.java>>

-derek



This message may contain privileged and/or confidential information.  If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so.  Thank you.

Attachment: TestCastorPerformance.java
Description: Binary data

Reply via email to