mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Performance improvements (#746)
* Misc minor performance improvements * Use more concise loop syntax * Use more concise Collection sort syntax * Use StringUtils pad methods * Optimize some loops and double-map-lookups * Optimize array instantiation There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation. * Cleanup string concatenation * Use EnumMap where possible * Use FastMath instead of Math * Initialize complex things only once * Reduce method size to aloow more JIT inlining * remove map of short->float * Move field to local variable * Cleanup Map lookup Co-authored-by: Rob Ekl <xwq876@zebra.com>
This commit is contained in:
@@ -25,18 +25,18 @@ public class ChannelMemoryLogger implements Runnable, ChannelEventListener
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( "CHAN TOT:" + mChannelCount );
|
||||
sb.append( " TRFC:" + mTrafficChannelCount );
|
||||
sb.append( " PROC:" + mChannelProcessingCount );
|
||||
sb.append("CHAN TOT:").append(mChannelCount);
|
||||
sb.append(" TRFC:").append(mTrafficChannelCount);
|
||||
sb.append(" PROC:").append(mChannelProcessingCount);
|
||||
|
||||
long maxMemory = runtime.maxMemory();
|
||||
long allocatedMemory = runtime.totalMemory();
|
||||
long freeMemory = runtime.freeMemory();
|
||||
|
||||
sb.append(" MEM FREE: " + format.format(freeMemory / 1024) );
|
||||
sb.append(" ALLOC: " + format.format(allocatedMemory / 1024) );
|
||||
sb.append(" MAX: " + format.format(maxMemory / 1024) );
|
||||
sb.append(" TOTAL: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) );
|
||||
sb.append(" MEM FREE: ").append(format.format(freeMemory / 1024));
|
||||
sb.append(" ALLOC: ").append(format.format(allocatedMemory / 1024));
|
||||
sb.append(" MAX: ").append(format.format(maxMemory / 1024));
|
||||
sb.append(" TOTAL: ").append(format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));
|
||||
|
||||
mLog.debug( sb.toString() );
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.dsheirer.gui.control;
|
||||
import io.github.dsheirer.buffer.CircularBuffer;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
@@ -135,7 +136,7 @@ public class ConstellationViewer extends JPanel implements Listener<Complex>
|
||||
* serves as the instantaneous amplitude of the demodulated signal
|
||||
*/
|
||||
double denominator = 1.0d / i;
|
||||
angle = Math.atan( (double)q * denominator );
|
||||
angle = FastMath.atan( (double)q * denominator );
|
||||
}
|
||||
|
||||
Ellipse2D.Double ellipse =
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.github.dsheirer.source.InvalidFrequencyException;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.SourceException;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -287,17 +288,17 @@ public class JFrequencyControl extends JPanel implements ISourceEventProcessor
|
||||
public void setFrequency(long frequency, boolean fireChangeEvent)
|
||||
{
|
||||
//Strip the digits higher than this one
|
||||
long lower = frequency % (long)(Math.pow(10, mPower + 1));
|
||||
long lower = frequency % (long)(FastMath.pow(10, mPower + 1));
|
||||
|
||||
//Set the value to int value of dividing by 10 to this power
|
||||
long value = (long)(lower / (long)(Math.pow(10, mPower)));
|
||||
long value = (long)(lower / (long)(FastMath.pow(10, mPower)));
|
||||
|
||||
set(value, fireChangeEvent);
|
||||
}
|
||||
|
||||
public long getFrequency()
|
||||
{
|
||||
return mValue * (long)Math.pow(10, mPower);
|
||||
return mValue * (long)FastMath.pow(10, mPower);
|
||||
}
|
||||
|
||||
public void increment()
|
||||
|
||||
@@ -337,8 +337,7 @@ public class MultipleFrequencyEditor extends JPanel
|
||||
*/
|
||||
public List<Long> getFrequencies()
|
||||
{
|
||||
List<Long> frequencies = new ArrayList<>();
|
||||
frequencies.addAll(mFrequencies);
|
||||
List<Long> frequencies = new ArrayList<>(mFrequencies);
|
||||
return frequencies;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.chart.NumberAxis;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -35,7 +36,7 @@ public class ComplexPhaseLineChart extends LineChart implements Listener<Reusabl
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(ComplexPhaseLineChart.class);
|
||||
|
||||
private static final Complex ANGLE_OFFSET_45_DEGREES = Complex.fromAngle(Math.PI / 4.0);
|
||||
private static final Complex ANGLE_OFFSET_45_DEGREES = Complex.fromAngle(FastMath.PI / 4.0);
|
||||
private ComplexCircularBuffer mComplexCircularBuffer;
|
||||
private ComplexGain mComplexGain = new ComplexGain(600.0f);
|
||||
private ObservableList<Data<Integer,Float>> mPhaseValues = FXCollections.observableArrayList();
|
||||
@@ -44,7 +45,7 @@ public class ComplexPhaseLineChart extends LineChart implements Listener<Reusabl
|
||||
public ComplexPhaseLineChart(int length)
|
||||
{
|
||||
super(new NumberAxis("Time", 1, length - 10, 2),
|
||||
new NumberAxis("Phase", -Math.PI, Math.PI, Math.PI / 2.0));
|
||||
new NumberAxis("Phase", -FastMath.PI, FastMath.PI, FastMath.PI / 2.0));
|
||||
|
||||
Series<Integer,Float> phaseSeries = new Series<>("Phase", mPhaseValues);
|
||||
ObservableList<Series<Integer,Float>> observableList = FXCollections.observableArrayList(phaseSeries);
|
||||
|
||||
@@ -28,6 +28,7 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.chart.NumberAxis;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -97,7 +98,7 @@ public class EyeDiagramChart extends LineChart implements Listener<SymbolDecisio
|
||||
{
|
||||
corrected[x] = samples[x].angle();
|
||||
|
||||
if(x > 0 && (Math.abs(corrected[x] - corrected[x - 1]) > Math.PI))
|
||||
if(x > 0 && (FastMath.abs(corrected[x] - corrected[x - 1]) > FastMath.PI))
|
||||
{
|
||||
phaseRolloverIndex = x;
|
||||
}
|
||||
@@ -109,11 +110,11 @@ public class EyeDiagramChart extends LineChart implements Listener<SymbolDecisio
|
||||
{
|
||||
if(corrected[x] > 0)
|
||||
{
|
||||
corrected[x] -= 2 * Math.PI;
|
||||
corrected[x] -= 2 * FastMath.PI;
|
||||
}
|
||||
else
|
||||
{
|
||||
corrected[x] += 2 * Math.PI;
|
||||
corrected[x] += 2 * FastMath.PI;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +85,7 @@ public class SampleXYChart extends PolarChart<XYChartItem> implements Listener<R
|
||||
|
||||
series.getItems().clear();
|
||||
|
||||
for(int x = 0; x < complexSamples.length; x++)
|
||||
{
|
||||
Complex sample = complexSamples[x];
|
||||
for (Complex sample : complexSamples) {
|
||||
series.getItems().add(new XYChartItem(sample.polarAngleDegrees(), sample.magnitude(), Color.BLUE));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package io.github.dsheirer.gui.preference;
|
||||
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
@@ -41,6 +42,7 @@ import javafx.stage.Window;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
@@ -52,7 +54,7 @@ public class PreferencesEditor extends Application
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(PreferencesEditor.class);
|
||||
|
||||
private Map<PreferenceEditorType,Node> mEditors = new HashMap<>();
|
||||
private Map<PreferenceEditorType,Node> mEditors = new EnumMap<>(PreferenceEditorType.class);
|
||||
private UserPreferences mUserPreferences;
|
||||
private HBox mParentBox;
|
||||
private TreeView mEditorSelectionTreeView;
|
||||
@@ -118,22 +120,14 @@ public class PreferencesEditor extends Application
|
||||
|
||||
private TreeItem recursivelyFindEditorType(TreeItem parent, PreferenceEditorType type)
|
||||
{
|
||||
ListIterator<TreeItem> li = parent.getChildren().listIterator();
|
||||
|
||||
while(li.hasNext())
|
||||
{
|
||||
TreeItem treeItem = li.next();
|
||||
|
||||
if(treeItem.getValue() instanceof PreferenceEditorType && (treeItem.getValue()).equals(type))
|
||||
{
|
||||
for (TreeItem treeItem : (Iterable<TreeItem>) parent.getChildren()) {
|
||||
if (treeItem.getValue() instanceof PreferenceEditorType && (treeItem.getValue()).equals(type)) {
|
||||
return treeItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
TreeItem item = recursivelyFindEditorType(treeItem, type);
|
||||
|
||||
if(item != null)
|
||||
{
|
||||
if (item != null) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user