mirror of
https://github.com/grafana/grafana.git
synced 2025-01-24 07:17:08 -06:00
HeatmapNG: pre-allocate arrays during calc (#51465)
This commit is contained in:
parent
cfbfacb152
commit
89b150ab58
@ -7072,10 +7072,10 @@ exports[`better eslint`] = {
|
||||
"public/app/features/transformers/calculateHeatmap/editor/helper.ts:2898656130": [
|
||||
[10, 37, 3, "Unexpected any. Specify a different type.", "193409811"]
|
||||
],
|
||||
"public/app/features/transformers/calculateHeatmap/heatmap.ts:2895010613": [
|
||||
"public/app/features/transformers/calculateHeatmap/heatmap.ts:992367420": [
|
||||
[65, 9, 52, "Do not use any type assertions.", "3480700880"],
|
||||
[306, 63, 29, "Do not use any type assertions.", "255738422"],
|
||||
[306, 89, 3, "Unexpected any. Specify a different type.", "193409811"]
|
||||
[321, 63, 29, "Do not use any type assertions.", "255738422"],
|
||||
[321, 89, 3, "Unexpected any. Specify a different type.", "193409811"]
|
||||
],
|
||||
"public/app/features/transformers/configFromQuery/ConfigFromQueryTransformerEditor.test.tsx:1060905279": [
|
||||
[44, 29, 21, "Do not use any type assertions.", "1548027068"]
|
||||
|
@ -244,9 +244,6 @@ export function prepBucketFrames(frames: DataFrame[]): DataFrame[] {
|
||||
export function calculateHeatmapFromData(frames: DataFrame[], options: HeatmapCalculationOptions): DataFrame {
|
||||
//console.time('calculateHeatmapFromData');
|
||||
|
||||
let xs: number[] = [];
|
||||
let ys: number[] = [];
|
||||
|
||||
// optimization
|
||||
//let xMin = Infinity;
|
||||
//let xMax = -Infinity;
|
||||
@ -254,6 +251,20 @@ export function calculateHeatmapFromData(frames: DataFrame[], options: HeatmapCa
|
||||
let xField: Field | undefined = undefined;
|
||||
let yField: Field | undefined = undefined;
|
||||
|
||||
let dataLen = 0;
|
||||
// pre-allocate arrays
|
||||
for (let frame of frames) {
|
||||
// TODO: assumes numeric timestamps, ordered asc, without nulls
|
||||
const x = frame.fields.find((f) => f.type === FieldType.time);
|
||||
if (x) {
|
||||
dataLen += frame.length;
|
||||
}
|
||||
}
|
||||
|
||||
let xs: number[] = Array(dataLen);
|
||||
let ys: number[] = Array(dataLen);
|
||||
let j = 0;
|
||||
|
||||
for (let frame of frames) {
|
||||
// TODO: assumes numeric timestamps, ordered asc, without nulls
|
||||
const x = frame.fields.find((f) => f.type === FieldType.time);
|
||||
@ -268,8 +279,12 @@ export function calculateHeatmapFromData(frames: DataFrame[], options: HeatmapCa
|
||||
const xValues = x.values.toArray();
|
||||
for (let field of frame.fields) {
|
||||
if (field !== x && field.type === FieldType.number) {
|
||||
xs = xs.concat(xValues);
|
||||
ys = ys.concat(field.values.toArray());
|
||||
const yValues = field.values.toArray();
|
||||
|
||||
for (let i = 0; i < xValues.length; i++, j++) {
|
||||
xs[j] = xValues[i];
|
||||
ys[j] = yValues[i];
|
||||
}
|
||||
|
||||
if (!yField) {
|
||||
yField = field;
|
||||
|
Loading…
Reference in New Issue
Block a user