From: Matthew Khouzam Date: Wed, 18 May 2016 15:19:28 +0000 (-0400) Subject: timing.core: Make ArrayList use the array of segments if possible X-Git-Url: http://git.efficios.com/?p=deliverable%2Ftracecompass.git;a=commitdiff_plain;h=aa9082f9ef0d8e9ac4355fd7ca9255c5347e7bc4 timing.core: Make ArrayList use the array of segments if possible Bulk load arrays if possible to speed up the serialized segment store. Change-Id: I55a389419b7fe3182ee3d0fae90c16d9c6bab5a2 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/73061 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisModule.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisModule.java index 0518880fdc..597b547e45 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisModule.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisModule.java @@ -23,6 +23,7 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.ListenerList; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.common.core.NonNullUtils; import org.eclipse.tracecompass.internal.analysis.timing.core.store.ArrayListStore; import org.eclipse.tracecompass.segmentstore.core.ISegment; import org.eclipse.tracecompass.segmentstore.core.ISegmentStore; @@ -146,13 +147,7 @@ public abstract class AbstractSegmentStoreAnalysisModule extends TmfAbstractAnal /* Attempt to read the existing file */ try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file))) { Object[] segmentArray = readObject(ois); - final ISegmentStore store = new ArrayListStore<>(); - for (Object element : segmentArray) { - if (element instanceof ISegment) { - ISegment segment = (ISegment) element; - store.add(segment); - } - } + ISegmentStore store = new ArrayListStore<>(NonNullUtils.checkNotNullContents(segmentArray)); fSegmentStore = store; sendUpdate(store); return true; diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/store/ArrayListStore.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/store/ArrayListStore.java index 0e1f494b30..86c67351ed 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/store/ArrayListStore.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/store/ArrayListStore.java @@ -62,7 +62,7 @@ public class ArrayListStore<@NonNull E extends ISegment> implements ISegmentStor private final ReadWriteLock fLock = new ReentrantReadWriteLock(false); - private final List fStore = new ArrayList<>(); + private final List fStore; private @Nullable transient Iterable fLastSnapshot = null; @@ -70,18 +70,25 @@ public class ArrayListStore<@NonNull E extends ISegment> implements ISegmentStor * Constructor */ public ArrayListStore() { - /* - * For the start times index, the "key comparator" will compare the - * start times as longs directly. This is the primary comparator for its - * tree map. - * - * The secondary "value" comparator will check the end times first. - * - * The same is done for the end times index, but swapping the first two - * comparators instead. - */ + fStore = new ArrayList<>(); } + /** + * Constructor + * + * @param array + * an array of elements to wrap in the segment store + * + */ + public ArrayListStore(Object[] array) { + fStore = new ArrayList<>(); + for (int i = 0; i < array.length; i++) { + if (array[i] instanceof ISegment) { + fStore.add((E) array[i]); + } + } + fStore.sort(COMPARATOR); + } // ------------------------------------------------------------------------ // Methods from Collection // ------------------------------------------------------------------------