Skip to content

Commit

Permalink
Optimize make_xy_column_data, now consistently achieves 2-6x speedup …
Browse files Browse the repository at this point in the history
…over row-based series generation
  • Loading branch information
sc1f committed Sep 19, 2018
1 parent 40e30d8 commit c455d1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
19 changes: 3 additions & 16 deletions packages/perspective-viewer-highcharts/src/js/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,9 @@ export const draw = (mode) => async function (el, view, task) {
num_aggregates = aggregates.length - hidden.length;

if (mode === 'scatter') {
let s;
let config = configs[0] = default_config.call(this, aggregates, mode);

// determine whether to use column/row data
if (col_pivots.length === 0) {
const cols = await view.to_columns();
s = await make_xy_column_data(cols, schema, aggregates.map(x => x.column), row_pivots, col_pivots, hidden);
} else {
js = await view.to_json();
s = await make_xy_data(js, schema, aggregates.map(x => x.column), row_pivots, col_pivots, hidden);
}

const series = s[0];
const xtop = s[1];
const colorRange = s[2];
const ytop = s[3];
const cols = await view.to_columns();
const [series, xtop, colorRange, ytop] = make_xy_column_data(cols, schema, aggregates.map(x => x.column), row_pivots, col_pivots, hidden);
const config = configs[0] = default_config.call(this, aggregates, mode);

config.legend.floating = series.length <= 20;
config.legend.enabled = col_pivots.length > 0;
Expand Down
43 changes: 20 additions & 23 deletions packages/perspective-viewer-highcharts/src/js/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class MakeTick {
}

if (cols.length === undefined) {
// Dealing with a ColumnIterator object - must map data to 2D array properly
// assign data to array in name order
data = [];
for (let name of col_names) {
data.push(cols[name]);
Expand All @@ -348,7 +348,6 @@ class MakeTick {

for (let i = 0; i < data[0].length; i++) {
if(data[0][i] === null || data[0][i] === undefined || data[0][i] === "") {
data[0][i] = null;
continue;
}

Expand All @@ -363,13 +362,11 @@ class MakeTick {
}

// set x-axis
tick.x = data[0][i];
tick.x = this.xaxis_clean.clean(tick.x);
tick.x = this.xaxis_clean.clean(data[0][i]);

if (num_cols > 1) {
// set y-axis
tick.y = data[1][i];
tick.y = this.yaxis_clean.clean(tick.y);
tick.y = this.yaxis_clean.clean(data[1][i]);
}

if (num_cols > 2) {
Expand Down Expand Up @@ -403,7 +400,7 @@ class MakeTick {
}
}

export async function make_xy_column_data(cols, schema, aggs, pivots, col_pivots, hidden) {
export function make_xy_column_data(cols, schema, aggs, pivots, col_pivots, hidden) {
const columns = new ColumnIterator(cols, hidden, pivots.length);
let series = [];
let color_range = [Infinity, -Infinity];
Expand Down Expand Up @@ -448,28 +445,28 @@ export async function make_xy_column_data(cols, schema, aggs, pivots, col_pivots
}

groups[group_name].push(col.data);
}

// FIXME: this is the heaviest loop
for (let name in groups) {
let ticks = make_tick.make_col(
groups[name],
aggs,
aggs.length,
columns.pivot_length,
row_path,
color_range,
);

let s = column_to_series(ticks, name);
series.push(s);
if (groups[group_name].length === aggs.length) {
// generate series as soon as we have enough data
let ticks = make_tick.make_col(
groups[group_name],
aggs,
aggs.length,
columns.pivot_length,
row_path,
color_range,
);

let s = column_to_series(ticks, group_name);
series.push(s);
}
}
}

return [series, {categories: make_tick.xaxis_clean.names}, color_range, {categories: make_tick.yaxis_clean.names}];
}

export async function make_xy_data(js, schema, columns, pivots, col_pivots, hidden) {
export function make_xy_data(js, schema, columns, pivots, col_pivots, hidden) {
let rows = new TreeAxisIterator(pivots.length, js);
let rows2 = new RowIterator(rows, hidden);
let series = [];
Expand Down Expand Up @@ -518,7 +515,7 @@ export async function make_xy_data(js, schema, columns, pivots, col_pivots, hidd
}
}
}

return [series, {categories: make_tick.xaxis_clean.names}, colorRange, {categories: make_tick.yaxis_clean.names}];
}

Expand Down

0 comments on commit c455d1e

Please sign in to comment.