Permalink
Browse files

Merge pull request #622 from AnalyticalGraphicsInc/performanceTweaks

Simple but effective performance improvements
  • Loading branch information...
2 parents ec20234 + 9dacebb commit 11b75e6ce3a6a77eb8aba826ab00f8c9acaa84d3 @kring kring committed Apr 9, 2013
@@ -62,6 +62,7 @@ define([
var fromPointsRitterCenter = new Cartesian3();
var fromPointsMinBoxPt = new Cartesian3();
var fromPointsMaxBoxPt = new Cartesian3();
+ var fromPointsNaiveCenterScratch = new Cartesian3();
/**
* Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
@@ -171,7 +172,7 @@ define([
maxBoxPt.y = yMax.y;
maxBoxPt.z = zMax.z;
- var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5);
+ var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
// Begin 2nd pass to find naive radius and modify the ritter sphere.
var naiveRadius = 0;
@@ -441,7 +442,7 @@ define([
maxBoxPt.y = yMax.y;
maxBoxPt.z = zMax.z;
- var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5);
+ var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
// Begin 2nd pass to find naive radius and modify the ritter sphere.
var naiveRadius = 0;
@@ -74,19 +74,7 @@ define(['./Math'
/**
* <p>
- * Interpolates values using the supplied interpolation algorithm. The appropriate subset of input
- * values to use for the interpolation is determined automatically from an interpolation given
- * degree.
- * </p>
- * <p>
- * The xTable array can contain any number of elements, and the appropriate subset will be
- * selected according to the degree of interpolation requested. For example, if degree is 5,
- * the 6 elements surrounding x will be used for interpolation. When using
- * {@link LinearApproximation} the degree should be 1 since it always deals with only 2 elements
- * surrounding x. The yTable array should contain a number of elements equal to:
- * <code>xTable.length * yStride</code>. If insufficient elements are provided
- * to perform the requested degree of interpolation, the highest possible degree of interpolation
- * will be performed.
+ * Interpolates values using Hermite Polynomial Approximation.
* </p>
*
* @param {Number} x The independent variable for which the dependent variables will be interpolated.
@@ -95,22 +83,33 @@ define(['./Math'
* in this array must be in increasing order and the same value must not occur twice in the array.
*
* @param {Array} yTable The array of dependent variables to use to interpolate. For a set of three
- * dependent values (p,q,w) and their derivatives (dp, dq, dw) at time 1 and time 2 this should be
- * as follows: {p1, q1, w1, dp1, dq1, dw1, p2, q2, w2, dp2, dq2, dw2}.
+ * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.
*
* @param {Number} yStride The number of dependent variable values in yTable corresponding to
* each independent variable value in xTable.
*
- * @returns An array of interpolated values. The array contains at least yStride elements, each
- * of which is an interpolated dependent variable value.
+ * @param {Array} [result] An existing array into which to store the result.
+ *
+ * @returns The array of interpolated values, or the result parameter if one was provided.
*
* @see LinearApproximation
* @see LagrangePolynomialApproximation
*
* @memberof HermitePolynomialApproximation
*/
- HermitePolynomialApproximation.interpolateOrderZero = function(x, xTable, yTable, yStride) {
- var length = xTable.length, i, j, d, s, len, index, result = new Array(yStride), coefficients = new Array(yStride);
+ HermitePolynomialApproximation.interpolateOrderZero = function(x, xTable, yTable, yStride, result) {
+ if (typeof result === 'undefined') {
+ result = new Array(yStride);
+ }
+
+ var i;
+ var j;
+ var d;
+ var s;
+ var len;
+ var index;
+ var length = xTable.length;
+ var coefficients = new Array(yStride);
for (i = 0; i < yStride; i++) {
result[i] = 0;
@@ -28,19 +28,7 @@ define(function() {
/**
* <p>
- * Interpolates values using the supplied interpolation algorithm. The appropriate subset of input
- * values to use for the interpolation is determined automatically from an interpolation given
- * degree.
- * </p>
- * <p>
- * The xTable array can contain any number of elements, and the appropriate subset will be
- * selected according to the degree of interpolation requested. For example, if degree is 5,
- * the 6 elements surrounding x will be used for interpolation. When using
- * {@link LinearApproximation} the degree should be 1 since it always deals with only 2 elements
- * surrounding x. The yTable array should contain a number of elements equal to:
- * <code>xTable.length * yStride</code>. If insufficient elements are provided
- * to perform the requested degree of interpolation, the highest possible degree of interpolation
- * will be performed.
+ * Interpolates values using Lagrange Polynomial Approximation.
* </p>
*
* @param {Number} x The independent variable for which the dependent variables will be interpolated.
@@ -49,26 +37,28 @@ define(function() {
* in this array must be in increasing order and the same value must not occur twice in the array.
*
* @param {Array} yTable The array of dependent variables to use to interpolate. For a set of three
- * dependent values (p,q,w) and their derivatives (dp, dq, dw) at time 1 and time 2 this should be
- * as follows: {p1, q1, w1, dp1, dq1, dw1, p2, q2, w2, dp2, dq2, dw2}.
+ * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.
*
* @param {Number} yStride The number of dependent variable values in yTable corresponding to
* each independent variable value in xTable.
*
- * @returns An array of interpolated values. The array contains at least yStride elements, each
- * of which is an interpolated dependent variable value.
+ * @param {Array} [result] An existing array into which to store the result.
+ *
+ * @returns The array of interpolated values, or the result parameter if one was provided.
*
* @see LinearApproximation
* @see HermitePolynomialApproximation
*
* @memberof LagrangePolynomialApproximation
- *
*/
- LagrangePolynomialApproximation.interpolateOrderZero = function(x, xTable, yTable, yStride) {
+ LagrangePolynomialApproximation.interpolateOrderZero = function(x, xTable, yTable, yStride, result) {
+ if (typeof result === 'undefined') {
+ result = new Array(yStride);
+ }
+
var i;
var j;
var length = xTable.length;
- var result = new Array(yStride);
for (i = 0; i < yStride; i++) {
result[i] = 0;
@@ -37,19 +37,7 @@ define([
/**
* <p>
- * Interpolates values using the supplied interpolation algorithm. The appropriate subset of input
- * values to use for the interpolation is determined automatically from an interpolation given
- * degree.
- * </p>
- * <p>
- * The xTable array can contain any number of elements, and the appropriate subset will be
- * selected according to the degree of interpolation requested. For example, if degree is 5,
- * the 6 elements surrounding x will be used for interpolation. When using
- * {@link LinearApproximation} the degree should be 1 since it always deals with only 2 elements
- * surrounding x. The yTable array should contain a number of elements equal to:
- * <code>xTable.length * yStride</code>. If insufficient elements are provided
- * to perform the requested degree of interpolation, the highest possible degree of interpolation
- * will be performed.
+ * Interpolates values using linear approximation.
* </p>
*
* @param {Number} x The independent variable for which the dependent variables will be interpolated.
@@ -58,36 +46,40 @@ define([
* in this array must be in increasing order and the same value must not occur twice in the array.
*
* @param {Array} yTable The array of dependent variables to use to interpolate. For a set of three
- * dependent values (p,q,w) and their derivatives (dp, dq, dw) at time 1 and time 2 this should be
- * as follows: {p1, q1, w1, dp1, dq1, dw1, p2, q2, w2, dp2, dq2, dw2}.
+ * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.
*
* @param {Number} yStride The number of dependent variable values in yTable corresponding to
* each independent variable value in xTable.
*
- * @returns An array of interpolated values. The array contains at least yStride elements, each
- * of which is an interpolated dependent variable value.
+ * @param {Array} [result] An existing array into which to store the result.
+ *
+ * @returns The array of interpolated values, or the result parameter if one was provided.
*
* @see LagrangePolynomialApproximation
* @see HermitePolynomialApproximation
*
- *
* @memberof LinearApproximation
*/
- LinearApproximation.interpolateOrderZero = function(x, xTable, yTable, yStride) {
+ LinearApproximation.interpolateOrderZero = function(x, xTable, yTable, yStride, result) {
if (xTable.length !== 2) {
throw new DeveloperError('The xTable provided to the linear interpolator must have exactly two elements.');
} else if (yStride <= 0) {
throw new DeveloperError('There must be at least 1 dependent variable for each independent variable.');
}
- var result = new Array(yStride), x0 = xTable[0], x1 = xTable[1], i, y0, y1;
+ if (typeof result === 'undefined') {
+ result = new Array(yStride);
+ }
- for (i = 0; i < yStride; i++) {
- //calculates the interpolated values
+ var i;
+ var y0;
+ var y1;
+ var x0 = xTable[0];
+ var x1 = xTable[1];
+ for (i = 0; i < yStride; i++) {
y0 = yTable[i];
y1 = yTable[i + yStride];
-
result[i] = (((y1 - y0) * x) + (x1 * y0) - (x0 * y1)) / (x1 - x0);
}
@@ -180,9 +180,8 @@ define([
}
var availabilityValue = availability.contains(time);
-
this._cachedAvailabilityDate = JulianDate.clone(time, this._cachedAvailabilityDate);
- this._cachedAvailabilityValue = availability.contains(time);
+ this._cachedAvailabilityValue = availabilityValue;
return availabilityValue;
};
@@ -45,6 +45,8 @@ define([
}
};
+ var cachedColor = new Color();
+ var cachedOutlineColor = new Color();
PolylineUpdater.prototype.updateObject = function(time, dynamicObject) {
var dynamicPath = dynamicObject.path;
if (typeof dynamicPath === 'undefined') {
@@ -155,12 +157,12 @@ define([
property = dynamicPath.color;
if (typeof property !== 'undefined') {
- polyline.setColor(property.getValue(time, polyline.getColor()));
+ polyline.setColor(property.getValue(time, cachedColor));
}
property = dynamicPath.outlineColor;
if (typeof property !== 'undefined') {
- polyline.setOutlineColor(property.getValue(time, polyline.getOutlineColor()));
+ polyline.setOutlineColor(property.getValue(time, cachedOutlineColor));
}
property = dynamicPath.outlineWidth;
@@ -168,6 +168,8 @@ define([
};
var cachedPosition = new Cartesian3();
+ var cachedColor = new Color();
+ var cachedOutlineColor = new Color();
DynamicPolylineVisualizer.prototype._updateObject = function(time, dynamicObject) {
var dynamicPolyline = dynamicObject.polyline;
if (typeof dynamicPolyline === 'undefined') {
@@ -233,12 +235,12 @@ define([
var property = dynamicPolyline.color;
if (typeof property !== 'undefined') {
- polyline.setColor(property.getValue(time, polyline.getColor()));
+ polyline.setColor(property.getValue(time, cachedColor));
}
property = dynamicPolyline.outlineColor;
if (typeof property !== 'undefined') {
- polyline.setOutlineColor(property.getValue(time, polyline.getOutlineColor()));
+ polyline.setOutlineColor(property.getValue(time, cachedOutlineColor));
}
property = dynamicPolyline.outlineWidth;
@@ -130,6 +130,8 @@ define([
}
};
+ var interpolationScratch;
+
/**
* Returns the value of the property at the specified time.
* @memberof DynamicProperty
@@ -139,6 +141,12 @@ define([
* @returns The modified result parameter or a new instance if the result parameter was not supplied.
*/
DynamicProperty.prototype.getValue = function(time, result) {
+ var valueType = this.valueType;
+
+ if (typeof this._staticValue !== 'undefined') {
+ return valueType.getValue(this._staticValue, result);
+ }
+
var interval = this._cachedInterval;
if (!JulianDate.equals(this._cachedTime, time)) {
this._cachedTime = JulianDate.clone(time, this._cachedTime);
@@ -152,8 +160,6 @@ define([
return undefined;
}
- var valueType = this.valueType;
-
var intervalData = interval.data;
var times = intervalData.times;
var values = intervalData.values;
@@ -228,13 +234,13 @@ define([
// Interpolate!
var x = times[lastIndex].getSecondsDifference(time);
- var interpolationResult = intervalData.interpolationAlgorithm.interpolateOrderZero(x, xTable, yTable, doublesPerInterpolationValue);
+ interpolationScratch = intervalData.interpolationAlgorithm.interpolateOrderZero(x, xTable, yTable, doublesPerInterpolationValue, interpolationScratch);
var specializedGetFunction = valueType.getValueFromInterpolationResult;
if (typeof specializedGetFunction === 'undefined') {
- return valueType.getValueFromArray(interpolationResult, 0, result);
+ return valueType.getValueFromArray(interpolationScratch, 0, result);
}
- return specializedGetFunction(interpolationResult, result, values, firstIndex, lastIndex);
+ return specializedGetFunction(interpolationScratch, result, values, firstIndex, lastIndex);
}
return valueType.getValueFromArray(intervalData.values, index * doublesPerValue, result);
}
@@ -340,11 +346,18 @@ define([
}
DynamicProperty._mergeNewSamples(epoch, intervalData.times, intervalData.values, unwrappedInterval, valueType.doublesPerValue, valueType);
intervalData.numberOfPoints = Math.min(intervalData.interpolationAlgorithm.getRequiredDataPoints(intervalData.interpolationDegree), intervalData.times.length);
+ this._staticValue = undefined;
} else {
//Packet itself is a constant value
intervalData.times = undefined;
intervalData.values = unwrappedInterval;
intervalData.isSampled = false;
+
+ if (existingInterval.equals(Iso8601.MAXIMUM_INTERVAL)) {
+ this._staticValue = unwrappedInterval;
+ } else {
+ this._staticValue = undefined;
+ }
}
};
@@ -371,6 +371,9 @@ define([
}
};
+ // Using unsigned short indices, 64K vertices can be indexed by one index buffer
+ var sixtyFourK = 64 * 1024;
+
/**
* DOC_TBA
*
@@ -389,10 +392,7 @@ define([
///////////////////////////////////////////////////////////////////////
- if (recreateVA || !this.va) {
- // Using unsigned short indices, 64K vertices can be indexed by one index buffer
- var sixtyFourK = 64 * 1024;
-
+ if (recreateVA || typeof this.vaByPurpose === 'undefined') {
var buffersByPurposeAndUsage = this._buffersByPurposeAndUsage;
this._destroyVA();
@@ -447,8 +447,9 @@ define([
var vertexBuffer = buffer.vertexBuffer;
var vertexBufferSizeInBytes = this._size * buffer.vertexSizeInBytes;
- if (!vertexBuffer || (vertexBuffer.getSizeInBytes() < vertexBufferSizeInBytes)) {
- if (vertexBuffer) {
+ var vertexBufferDefined = typeof vertexBuffer !== 'undefined';
+ if (!vertexBufferDefined || (vertexBuffer.getSizeInBytes() < vertexBufferSizeInBytes)) {
+ if (vertexBufferDefined) {
vertexBuffer.destroy();
}
buffer.vertexBuffer = this._context.createVertexBuffer(buffer.arrayBuffer, buffer.usage);
Oops, something went wrong.

0 comments on commit 11b75e6

Please sign in to comment.