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:
@@ -264,11 +264,9 @@ public class DFTProcessor implements Listener<ReusableComplexBuffer>, ISourceEve
|
||||
*/
|
||||
private void dispatch(float[] results)
|
||||
{
|
||||
Iterator<DFTResultsConverter> it = mListeners.iterator();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
it.next().receive(results);
|
||||
for (DFTResultsConverter mListener : mListeners) {
|
||||
mListener.receive(results);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import io.github.dsheirer.settings.SettingsManager;
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.BasicStroke;
|
||||
@@ -326,7 +327,7 @@ public class OverlayPanel extends JPanel implements Listener<ChannelEvent>, ISou
|
||||
|
||||
if(mZoom != 0)
|
||||
{
|
||||
graphics.drawString("Zoom: " + (int)Math.pow(2.0, mZoom) + "x", mCursorLocation.x + 17,
|
||||
graphics.drawString("Zoom: " + (int)FastMath.pow(2.0, mZoom) + "x", mCursorLocation.x + 17,
|
||||
mCursorLocation.y + 11);
|
||||
}
|
||||
}
|
||||
@@ -504,7 +505,7 @@ public class OverlayPanel extends JPanel implements Listener<ChannelEvent>, ISou
|
||||
|
||||
double offset = xAxis / width;
|
||||
|
||||
long frequency = getMinDisplayFrequency() + Math.round((double)getDisplayBandwidth() * offset);
|
||||
long frequency = getMinDisplayFrequency() + FastMath.round((double)getDisplayBandwidth() * offset);
|
||||
|
||||
if(frequency > (getMaxFrequency()))
|
||||
{
|
||||
@@ -761,7 +762,7 @@ public class OverlayPanel extends JPanel implements Listener<ChannelEvent>, ISou
|
||||
|
||||
public boolean containsFrequency(long frequency)
|
||||
{
|
||||
return Math.abs(mFrequency - frequency) <= (mBandwidth / 2);
|
||||
return FastMath.abs(mFrequency - frequency) <= (mBandwidth / 2);
|
||||
}
|
||||
|
||||
private long getMinDisplayFrequency()
|
||||
@@ -780,7 +781,7 @@ public class OverlayPanel extends JPanel implements Listener<ChannelEvent>, ISou
|
||||
{
|
||||
if(mZoom != 0)
|
||||
{
|
||||
return mBandwidth / (int)Math.pow(2.0, mZoom);
|
||||
return mBandwidth / (int)FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
return mBandwidth;
|
||||
@@ -862,14 +863,14 @@ public class OverlayPanel extends JPanel implements Listener<ChannelEvent>, ISou
|
||||
double maxLabels = ((double)OverlayPanel.this.getWidth() * LABEL_FILL_THRESHOLD) / (double)maxLabelWidth;
|
||||
|
||||
//Calculate the next smallest base 10 value for the major increment
|
||||
int power = (int)Math.log10((double)getDisplayBandwidth() / maxLabels);
|
||||
int power = (int)FastMath.log10((double)getDisplayBandwidth() / maxLabels);
|
||||
|
||||
//Set the number of decimal places to display in frequency labels
|
||||
int precision = 5 - power;
|
||||
|
||||
int start = (int)Math.pow(10.0, power + 1);
|
||||
int start = (int)FastMath.pow(10.0, power + 1);
|
||||
|
||||
int minimum = (int)Math.pow(10.0, power);
|
||||
int minimum = (int)FastMath.pow(10.0, power);
|
||||
|
||||
int labelIncrement = start;
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import io.github.dsheirer.spectrum.menu.FrameRateItem;
|
||||
import io.github.dsheirer.spectrum.menu.SmoothingItem;
|
||||
import io.github.dsheirer.spectrum.menu.SmoothingTypeItem;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -312,7 +313,7 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
|
||||
|
||||
public int getZoomMultiplier()
|
||||
{
|
||||
return (int)Math.pow(2.0, mZoom);
|
||||
return (int) FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ import io.github.dsheirer.settings.Setting;
|
||||
import io.github.dsheirer.settings.SettingChangeListener;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -303,7 +304,7 @@ public class SpectrumPanel extends JPanel implements DFTResultsListener, Setting
|
||||
{
|
||||
Validate.isTrue(2.0 <= sampleSize && sampleSize <= 64.0);
|
||||
|
||||
mDBScale = (float)(20.0 * Math.log10(Math.pow(2.0, sampleSize - 1)));
|
||||
mDBScale = (float)(20.0 * FastMath.log10(FastMath.pow(2.0, sampleSize - 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,7 +388,7 @@ public class SpectrumPanel extends JPanel implements DFTResultsListener, Setting
|
||||
|
||||
private int getZoomMultiplier()
|
||||
{
|
||||
return (int)Math.pow(2.0, mZoom);
|
||||
return (int) FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
import io.github.dsheirer.settings.SettingChangeListener;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -183,7 +184,7 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
|
||||
*/
|
||||
private int getZoomMultiplier()
|
||||
{
|
||||
return (int)Math.pow(2.0, mZoom);
|
||||
return (int) FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package io.github.dsheirer.spectrum.converter;
|
||||
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
/**
|
||||
* Converts complex DFT output to scaled dB values with a maximum amplitude of
|
||||
* 0 dB and all values scaled to the minimum dB value which is:
|
||||
@@ -85,7 +87,7 @@ public class ComplexDecibelConverter extends DFTResultsConverter
|
||||
//Calculate the magnitude squared (power) value from each bin's real
|
||||
//and imaginary value and scale it to the DFT bin size squared.
|
||||
//Convert the scaled value to decibels.
|
||||
float decibels = 10.0f * (float)Math.log10(
|
||||
float decibels = 10.0f * (float) FastMath.log10(
|
||||
( ( results[ x ] * results[ x ] ) +
|
||||
( results[ x + 1 ] * results[ x + 1 ] ) ) * dftBinSizeScalor );
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.dsheirer.spectrum.converter;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class RealDecibelConverter extends DFTResultsConverter
|
||||
{
|
||||
index = x * 2;
|
||||
|
||||
processed[ x ] = 20.0f * (float)Math.log10(
|
||||
processed[ x ] = 20.0f * (float) FastMath.log10(
|
||||
( ( results[ index ] * results[ index ] ) +
|
||||
( results[ index + 1 ] * results[ index + 1 ] ) ) * dftBinSizeScalor );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user