Hi,
I start this thread to gather some constructive comments on xith.
So here’s my first contribution :
REDUCING GC OVERHEAD
I’ve profiled the CubeTest application to gather some stats on xith memory usage, and here’s where most of the time is spent (gc-wise) :
- RenderBin. sortByShaders() (and other sort methods if used) : uses Arrays.sort() and thus allocates a new RenderBucket[3000] every frame.
Here’s the quicksort (copyright sir Gosling, and me ) I’ve added in RenderBin to stop it :
/** This is a generic version of C.A.R Hoare's Quick Sort
* algorithm. This will handle arrays that are already
* sorted, and arrays with duplicate keys.
*
* If you think of a one dimensional array as going from
* the lowest index on the left to the highest index on the right
* then the parameters to this function are lowest index or
* left and highest index or right. The first time you call
* this function it will be with the parameters 0, a.length - 1.
*
* @param a an object array
* @param lo0 left boundary of array partition
* @param hi0 right boundary of array partition
* @param comp the comparator used
*/
private static void quickSort(Object a[], int lo0, int hi0, Comparator comp) {
int lo = lo0;
int hi = hi0;
Object mid;
if ( hi0 > lo0) {
/* Arbitrarily establishing partition element as the midpoint of
* the array.
*/
mid = a[ ( lo0 + hi0 ) / 2 ];
// loop through the array until indices cross
while( lo <= hi ){
/* find the first element that is greater than or equal to
* the partition element starting from the left Index.
*/
while( ( lo < hi0 ) && ( comp.compare(a[lo],mid) < 0 ) ){
++lo;
}
/* find an element that is smaller than or equal to
* the partition element starting from the right Index.
*/
while( ( hi > lo0 ) && ( comp.compare(a[hi], mid)>0 ) ){
--hi;
}
// if the indexes have not crossed, swap
if( lo <= hi ) {
swap(a, lo, hi);
++lo;
--hi;
}
}
/* If the right index has not reached the left side of array
* must now sort the left partition.
*/
if( lo0 < hi )
quickSort( a, lo0, hi , comp);
/* If the left index has not reached the right side of array
* must now sort the right partition.
*/
if( lo < hi0 )
quickSort( a, lo, hi0 , comp);
}
}
private static void swap(Object a[], int i, int j)
{
Object T;
T = a[i];
a[i] = a[j];
a[j] = T;
}
Then just update the sort methods …
public void sortByShaders() {
quickSort(buckets, 0, curSize-1, stateComparator);
// Arrays.sort(buckets,0,curSize,stateComparator);
}
Lilian
edited : typos