Permalink
Browse files

One more GC-related improvement, need 0.7.1 build

  • Loading branch information...
1 parent 24be25b commit d1c9b0771b400e72d8eaba35d09a4911efc4a980 @cowtowncoder committed May 30, 2012
Showing with 9 additions and 13 deletions.
  1. +1 −2 release-notes/VERSION
  2. +8 −11 src/main/java/com/fasterxml/sort/Sorter.java
View
@@ -1,4 +1,4 @@
-Version: 0.7.0
+Version: 0.7.1
Release date:
29-May-2012
@@ -15,5 +15,4 @@ Fixes:
=== History: ===
------------------------------------------------------------------------
-2.0.2 (16-May-2012)
@@ -225,9 +225,11 @@ public boolean sort(DataReader<T> inputReader, DataWriter<T> resultWriter)
inputReader.close();
_phase = SortingState.Phase.SORTING;
_writeAll(resultWriter, items);
- } else {
- // but if more data than memory-buffer-full, do it right:
- List<File> presorted = presort(inputReader, buffer, items, next);
+ } else { // but if more data than memory-buffer-full, do it right:
+ List<File> presorted = new ArrayList<File>();
+ presorted.add(_writePresorted(items));
+ items = null; // it's a big array, clear refs as early as possible
+ _presort(inputReader, buffer, next, presorted);
inputClosed = true;
inputReader.close();
_phase = SortingState.Phase.SORTING;
@@ -312,21 +314,16 @@ public boolean sort(DataReader<T> inputReader, DataWriter<T> resultWriter)
return buffer.completeAndClearBuffer(segment, ptr);
}
- protected List<File> presort(DataReader<T> inputReader,
- SegmentedBuffer buffer,
- Object[] firstSortedBatch, T nextValue) throws IOException
+ protected void _presort(DataReader<T> inputReader, SegmentedBuffer buffer, T nextValue,
+ List<File> presorted)
+ throws IOException
{
- ArrayList<File> presorted = new ArrayList<File>();
- presorted.add(_writePresorted(firstSortedBatch));
- // important: clear out the ref to let possibly sizable array to be GCed
- firstSortedBatch = null;
do {
Object[] items = _readMax(inputReader, buffer, _config.getMaxMemoryUsage(), nextValue);
Arrays.sort(items, _rawComparator());
presorted.add(_writePresorted(items));
nextValue = inputReader.readNext();
} while (nextValue != null);
- return presorted;
}
protected File _writePresorted(Object[] items) throws IOException

2 comments on commit d1c9b07

ok maybe this is where the fix is.. :) (my previous comment about the nulling out not actually helping looks like is addressed in this commit).

Owner

cowtowncoder replied May 30, 2012

Right -- I noticed that omission, but only after submitting 0.7.0 build. :-)

Please sign in to comment.