ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 50200] VectorSet kills the performance of DirectoryScanner
Date Mon, 13 Dec 2010 09:40:32 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=50200

--- Comment #1 from Stefan Bodewig <bodewig@apache.org> 2010-12-13 04:40:28 EST ---
I'm afraid your patch relies on Vector's implementation details which are not
documented.  Let's assume Vector's add() method was implemented like

public synchronized boolean add(Object o) {
    add(size(), o);
    return true;
}

then invoking VectorSet#add(Object) would add the object to the set, invoke
super.add(Object) which in turn invokes VectorSet#add(int,Object) getting back
to doAdd(int,Object) which will then not add the object at all because
it already is inside the set.

The real problem seems to be that we perform arraycopy even if we don't need
to in the index==size() case so I wonder whether a patch like

Index: src/main/org/apache/tools/ant/util/VectorSet.java
===================================================================
--- src/main/org/apache/tools/ant/util/VectorSet.java   (revision 1040588)
+++ src/main/org/apache/tools/ant/util/VectorSet.java   (working copy)
@@ -77,12 +77,14 @@
         // is not documented so we may better implement it ourselves
         if (set.add(o)) {
             ensureCapacity(size() + 1);
+            if (index != size()) {
             Object[] elems = new Object[elementData.length];
             System.arraycopy(elementData, 0, elems, 0, index);
-            elems[index] = o;
             System.arraycopy(elementData, index, elems, index + 1,
                              size() - index);
             elementData = elems;
+            }
+            elementData[index] = o;
             elementCount++;
         }
     }

wouldn't achive the same performance improvement without inoking any base class
methods at all.

Is there any chance you could check my suggested patch in your environment?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message