Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace fixes #858

Merged
merged 5 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 43 additions & 37 deletions packages/perspective-bench/bench/perspective.benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ describe("Table", async () => {
});

for (const name of Object.keys(data)) {
describe(name, () => {
benchmark("table()", async () => {
let test = data[name];
table = worker.table(test.slice ? test.slice() : test);
await table.size();
describe("mixed", async () => {
describe("table", () => {
benchmark(name, async () => {
let test = data[name];
table = worker.table(test.slice ? test.slice() : test);
await table.size();
});
});
});
}
Expand All @@ -79,36 +81,40 @@ describe("View", async () => {
for (const column_pivot of COLUMN_PIVOT_OPTIONS) {
const config = {aggregate, row_pivot, column_pivot};

describe(to_name(config), async () => {
let view;
const [cat, type] = to_name(config);

afterEach(async () => {
await view.delete();
});
describe(type, async () => {
describe(cat, async () => {
let view;

benchmark(`view()`, async () => {
view = table.view(config);
await view.schema();
});
});

describe(to_name(config), async () => {
let view;
afterEach(async () => {
await view.delete();
});

beforeAll(async () => {
view = table.view(config);
await view.schema();
benchmark(`view`, async () => {
view = table.view(config);
await view.schema();
});
});

afterAll(async () => {
await view.delete();
});
describe(cat, async () => {
let view;

beforeAll(async () => {
view = table.view(config);
await view.schema();
});

for (const format of ["to_json", "to_columns", "to_arrow"]) {
benchmark(`${format}()`, async () => {
await view[format]();
afterAll(async () => {
await view.delete();
});
}

for (const format of ["json", "columns", "arrow"]) {
benchmark(format, async () => {
await view[`to_${format}`]();
});
}
});
});
}
}
Expand All @@ -126,14 +132,14 @@ const wait_for_perspective = () => new Promise(resolve => window.addEventListene
function to_name({aggregate, row_pivot, column_pivot}) {
const type = COLUMN_TYPES[aggregate[0].column];
const sides = {
"00": "0 Sided",
"10": "1 Sided",
"20": "1 Sided (Deep)",
"21": "2 Sided (Deep)",
"11": "2 Sided",
"01": "2 Sided (Column Only)"
"00": "ctx0",
"10": "ctx1",
"20": "ctx1 deep",
"21": "ctx2 deep",
"11": "ctx2",
"01": "ctx1.5"
}[row_pivot.length.toString() + column_pivot.length.toString()];
return `${sides}, ${type}`;
return [`${sides}`, type];
// return `${COLUMN_TYPES[aggregate[0].column]},${row_pivot.join("/") || "-"}*${column_pivot.join("/") || "-"}`;
}

Expand Down Expand Up @@ -176,12 +182,12 @@ async function get_data_browser(worker) {
console.log("Generating JSON");
const tbl = worker.table(arrow.slice());
const view = tbl.view();
const rows = await view.to_json();
const json = await view.to_json();
const columns = await view.to_columns();
view.delete();
tbl.delete();

return {csv, arrow, rows, columns};
return {csv, arrow, json, columns};
}

async function get_data_node(worker) {
Expand Down
5 changes: 4 additions & 1 deletion packages/perspective-bench/bench/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const FINOS_VERSIONS = ["0.3.1", "0.3.0", "0.3.0-rc.3", "0.3.0-rc.2", "0.3.0-rc.
const UMD_VERSIONS = ["0.3.9", "0.3.8", "0.3.7", "0.3.6"];

async function run() {
await PerspectiveBench.run("master", "bench/perspective.benchmark.js", `http://host.docker.internal:8080/perspective.js`, {output: "dist/benchmark", puppeteer: true});
await PerspectiveBench.run("master", "bench/perspective.benchmark.js", `http://${process.env.PSP_DOCKER_PUPPETEER ? `localhost` : `host.docker.internal`}:8080/perspective.js`, {
output: "dist/benchmark",
puppeteer: true
});

for (const version of UMD_VERSIONS) {
const url = `https://unpkg.com/@finos/perspective@${version}/dist/umd/perspective.js`;
Expand Down
4 changes: 4 additions & 0 deletions packages/perspective-bench/src/js/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const perspective = require("@finos/perspective");
const chalk = require("chalk");
const program = require("commander");

const execSync = require("child_process").execSync;

chalk.enabled = true;
chalk.level = 1;

Expand Down Expand Up @@ -99,6 +101,8 @@ exports.run = async function run(version, benchmark, ...cmdArgs) {
args: ["--no-sandbox"]
});

execSync(`renice -n -20 ${browser.process().pid}`, {stdio: "inherit"});

bins = await run_version(browser, cmdArgs, RUN_TEST);

await browser.close();
Expand Down
116 changes: 98 additions & 18 deletions packages/perspective-bench/src/js/browser_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const ITERATIONS = 100;
const ITERATION_TIME = 500;
const TOSS_ITERATIONS = 0;
const INDENT_LEVEL = 2;
const MIN_TIMEOUT = 0;
const OUTPUT_MODE = "flat";

async function* filterOutliers(someArray) {
const values = [],
Expand Down Expand Up @@ -38,59 +40,135 @@ function quotechalk(x) {
return x.replace(/\{/g, "\\{").replace(/\}/g, "\\}");
}

function to_table(col_lengths, padding = 0) {
return function(...row) {
try {
let result = "".padStart(padding - 2, " ");
for (let c = 0; c < row.length; ++c) {
let method = "padEnd";
let col_length = col_lengths[c];
if (Array.isArray(col_length)) {
[method, col_length] = col_length;
}
col_length = col_length || 0;
const cell = row[c];
let real_cell = cell.replace(/{[a-zA-Z]+? ([^{]+?)}/g, "$1");
let real_cell_length = cell.length;
while (real_cell.length < real_cell_length) {
real_cell_length = real_cell.length;
real_cell = cell.replace(/{[a-zA-Z]+? ([^{]+?)}/g, "$1");
}

if (col_length < real_cell.length) {
col_length = real_cell.length;
col_lengths[c] = [method, col_length];
}
const cell_length = cell.length + Math.max(0, col_length - real_cell.length);
result += " " + cell[method].call(cell, cell_length, " ");
}
console.log(result);
} catch (e) {
console.error(e.message);
}
};
}

let PRINTER, LAST_PATH;

class Benchmark {
constructor(desc, body, indent, categories, after_each, iterations, timeout, toss) {
constructor(desc, path, body, indent, categories, after_each, iterations, timeout, toss) {
this._desc = quotechalk(desc);
this._body = body;
this._path = path.slice(0, path.length - 2);
this._indent = indent;
this._after_each = after_each;
this._categories = categories;
this._iterations = iterations;
this._timeout = timeout;
this._toss = toss;

const iter_length = Math.log10(ITERATIONS) * 2 + 3;
const per_length = 9;
this._table_printer = PRINTER =
PRINTER ||
to_table(
[
...(OUTPUT_MODE === "tree" ? [...path.map(() => undefined), undefined] : []),
["padStart", iter_length],
["padStart", per_length],
["padStart", undefined],
["padStart", undefined],
["padStart", undefined]
],
OUTPUT_MODE === "grouped" ? (indent - 1) * INDENT_LEVEL : " "
);
}

log(reps, t) {
const completed = reps - this._toss();
const total = this._iterations() - this._toss();
log(reps, totals) {
const t = totals.reduce((x, y) => x + y);
const mean = t / reps;
const stddev = Math.sqrt(totals.map(x => Math.pow(x - mean, 2)).reduce((x, y) => x + y) / reps) / mean;
const completed = reps;
const total = this._iterations();
const time = t / 1000;
const completed_per = completed / total;
const time_per = time / completed;
const color = completed_per < 0.33 ? "redBright" : completed_per < 0.66 ? "yellowBright" : "greenBright";
let log = " ".repeat(this._indent + INDENT_LEVEL);
log += `{${color} ${completed}}{whiteBright /${total} `;
log += `({${color} ${(100 * completed_per).toFixed(2)}}%)}`;
log += ` {whiteBright ${time.toFixed(3)}}s {whiteBright ${time_per.toFixed(2)}} secs/op`;
log += ` {whiteBright ${this._desc}}`;

console.log(log);
const color = completed_per >= 1 ? "white" : completed_per < 0.33 ? "redBright" : completed_per < 0.66 ? "yellowBright" : "greenBright";
const stddev_color = stddev < 0.25 ? "greenBright" : stddev < 0.5 ? "yellowBright" : "redBright";
const path = [...this._path.reverse(), this._desc];
const last_path = path.slice();
if (LAST_PATH) {
for (let x = 0; x < path.length; ++x) {
if (path[x] === LAST_PATH[x]) {
path[x] = "-";
if (x > 0) {
path[x - 1] = "";
}
} else {
break;
}
}
}
LAST_PATH = last_path;
this._table_printer(
...(OUTPUT_MODE === "tree" ? path : []),
`{${color} ${completed}}{whiteBright /${total}}`,
`({${color} ${(100 * completed_per).toFixed(2)}}{whiteBright %)}`,
`{whiteBright ${time.toFixed(3)}}s`,
`{whiteBright ${time_per.toFixed(2)}}secs/op`,
`{${stddev_color} ${(100 * stddev).toFixed(2)}}{whiteBright %} σ/mean`,
...(OUTPUT_MODE === "flat" ? this._path : []),
...(OUTPUT_MODE === "tree" ? [] : [`{whiteBright ${this._desc}}`])
);
}

*case_iter() {
let x, start, now;
for (x = 0; x < this._iterations() + this._toss(); x++) {
for (x = 0; !start || performance.now() - start < MIN_TIMEOUT || x < this._iterations() + this._toss(); x++) {
if (x >= this._toss() && start == undefined) {
start = Date.now();
start = performance.now();
}
now = Date.now();
now = performance.now();
if (now - start > this._timeout()) {
this.log(x, now - start);
return;
}

yield x >= this._toss();
}
this.log(x, now - start);
}

async *run() {
try {
const categories = this._categories();
let count = 0,
totals = [];
for (const not_warmup of this.case_iter(this._desc)) {
const start = performance.now();
await this._body();
const stop = performance.now() - start;
if (not_warmup) {
totals.push(stop);
count += 1;
yield {
test: this._desc,
time: stop,
Expand All @@ -101,6 +179,7 @@ class Benchmark {
await this._after_each();
}
}
this.log(count, totals);
} catch (e) {
console.error(`Benchmark ${this._desc} failed`, e);
}
Expand Down Expand Up @@ -136,6 +215,7 @@ class Suite {
context._benchmarks.push(
new Benchmark(
desc,
this._context.map(x => x._name),
body,
context._indent,
() => unwind(stack),
Expand Down Expand Up @@ -188,7 +268,7 @@ class Suite {

async *run_all_cases() {
this._context.unshift(this);
if (this._name) {
if (this._name && OUTPUT_MODE === "grouped") {
console.log(`${" ".repeat(this._indent)}{whiteBright ${this._name}}`);
}
if (this._body) {
Expand Down
1 change: 1 addition & 0 deletions packages/perspective-phosphor/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"noImplicitAny": true,
"noEmitOnError": true,
"noUnusedLocals": true,
Expand Down
43 changes: 12 additions & 31 deletions packages/perspective-phosphor/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,16 @@
*/

const path = require("path");
const webpack = require("webpack");
const common = require("@finos/perspective/src/config/common.config.js");

module.exports = {
mode: process.env.PSP_NO_MINIFY || process.env.PSP_DEBUG ? "development" : process.env.NODE_ENV || "production",
entry: path.join(__dirname, "../dist/esm/index.js"),
devtool: "source-map",
resolve: {
extensions: [".ts", ".js", ".json"]
},
externals: [/^[a-z0-9@]/],
plugins: [new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /(en|es|fr)$/)],
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
stats: {modules: false, hash: false, version: false, builtAt: false, entrypoints: false},
module: {
rules: [
{
test: /\.less$/,
use: [{loader: "css-loader"}, {loader: "less-loader"}]
},
{test: /\.ts?$/, loader: "ts-loader", options: {configFile: "config/tsconfig.json"}}
]
},
output: {
filename: "index.js",
libraryTarget: "commonjs",
path: path.resolve(__dirname, "../dist/cjs")
}
};
module.exports = common({}, config =>
Object.assign(config, {
entry: path.join(__dirname, "../dist/esm/index.js"),
externals: [/^[a-z0-9@]/],
output: {
filename: "index.js",
libraryTarget: "commonjs",
path: path.resolve(__dirname, "../dist/cjs")
}
})
);
Loading