Commit performance

Hi

In one of our tests there is a “massive” inserts (~25000 rows) that we find quite long (several minutes), so we started profiling.

It appears that this eclipse method is a hot spot: org.eclipse.persistence.descriptors.ClassDescriptor.getMappingForAttributeName.

image

Which by looking at the code is not surprising

     * PUBLIC:
     * Returns the mapping associated with a given attribute name.
     * This can be used to find a descriptors mapping in a amendment method before the descriptor has been initialized.
     */
    public DatabaseMapping getMappingForAttributeName(String attributeName) {
        // ** Don't use this internally, just for amendments, see getMappingForAttributeName on ObjectBuilder.
        for (Enumeration mappingsNum = mappings.elements(); mappingsNum.hasMoreElements();) {
            DatabaseMapping mapping = (DatabaseMapping)mappingsNum.nextElement();
            if ((mapping.getAttributeName() != null) && mapping.getAttributeName().equals(attributeName)) {
                return mapping;
            }
        }
        return null;
    }

This method as a linear complexity while it is called systematically it seems. Using a HashMap instead of iterating over an Enumeration could drastically improve performance.

Incidentally, this is how the same method is implemented in org.eclipse.persistence.internal.descriptors.ObjectBuilder

Best Regards
Michael

1 Like

Hi,
Time for this method is only 9%. It is very small compared to the main time.
If you don’t use references to committed instances in your test, try to set performance optimization CommitContext#setDiscardCommitted(true). It skips committed instances processing and updateReferences

Which in this case will save 86% of the time, that’s quite good !