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

Replace atomic #603

Merged
merged 5 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Made replace() method atomic
  • Loading branch information
texodus committed May 29, 2019
commit 543f7f5ec40c3eac027dba8c2176d2c4201d775f
2 changes: 1 addition & 1 deletion packages/perspective-bench/bench/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const JPMC_VERSIONS = [
"0.2.0"
];

const FINOS_VERSIONS = ["0.3.0-rc.1"];
const FINOS_VERSIONS = ["0.3.0-rc.3", "0.3.0-rc.2", "0.3.0-rc.1"];

async function run() {
await PerspectiveBench.run("master", "bench/perspective.benchmark.js", `http://host.docker.internal:8080/perspective.js`, {output: "build/benchmark", puppeteer: true});
Expand Down
23 changes: 15 additions & 8 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default function(Module) {
}
}

function _reset_process(pool) {
_POOL_DEBOUNCES = _POOL_DEBOUNCES.filter(x => x !== pool);
}

/**
* Common logic for creating and registering a gnode/t_table.
*
Expand Down Expand Up @@ -283,8 +287,8 @@ export default function(Module) {
* View objects do not stop consuming resources or processing updates when
* they are garbage collected - you must call this method to reclaim these.
*/
view.prototype.delete = async function() {
await new Promise(setTimeout);
view.prototype.delete = function() {
_reset_process(this.pool);
this._View.delete();
this.ctx.delete();

Expand Down Expand Up @@ -364,7 +368,7 @@ export default function(Module) {
return extract_vector_scalar(this._View.column_names(skip, depth)).map(x => x.join(defaults.COLUMN_SEPARATOR_STRING));
};

view.prototype.get_data_slice = async function(start_row, end_row, start_col, end_col) {
view.prototype.get_data_slice = function(start_row, end_row, start_col, end_col) {
const num_sides = this.sides();
const nidx = ["zero", "one", "two"][num_sides];
return __MODULE__[`get_data_slice_${nidx}`](this._View, start_row, end_row, start_col, end_col);
Expand All @@ -376,7 +380,7 @@ export default function(Module) {
* @private
*/
const to_format = async function(options, formatter) {
await new Promise(setTimeout);
_clear_process(this.pool);
options = options || {};
const max_cols = this._View.num_columns() + (this.sides() === 0 ? 0 : 1);
const max_rows = this._View.num_rows();
Expand All @@ -391,7 +395,7 @@ export default function(Module) {
const num_sides = this.sides();
const nidx = ["zero", "one", "two"][num_sides];

const slice = await this.get_data_slice(start_row, end_row, start_col, end_col);
const slice = this.get_data_slice(start_row, end_row, start_col, end_col);
const ns = slice.get_column_names();
const col_names = extract_vector_scalar(ns).map(x => x.join(defaults.COLUMN_SEPARATOR_STRING));

Expand Down Expand Up @@ -452,7 +456,7 @@ export default function(Module) {
let slice;

if (!options.data_slice) {
const data_slice = await this.get_data_slice(start_row, end_row, idx, idx + 1);
const data_slice = this.get_data_slice(start_row, end_row, idx, idx + 1);
slice = data_slice.get_slice();
} else {
slice = options.data_slice.get_column_slice(idx);
Expand Down Expand Up @@ -881,27 +885,30 @@ export default function(Module) {
* construction options.
*/
table.prototype.clear = function() {
_reset_process(this.pool);
this.gnode.reset();
};

/**
* Replace all rows in this {@link module:perspective~table} the input data.
*/
table.prototype.replace = function(data) {
_reset_process(this.pool);
this.gnode.reset();
this.update(data);
_clear_process(this.pool);
};

/**
* Delete this {@link module:perspective~table} and clean up all resources associated with it.
* Table objects do not stop consuming resources or processing updates when
* they are garbage collected - you must call this method to reclaim these.
*/
table.prototype.delete = async function() {
await new Promise(setTimeout);
table.prototype.delete = function() {
if (this.views.length > 0) {
throw "Table still has contexts - refusing to delete.";
}
_reset_process(this.pool);
this.pool.unregister_gnode(this.gnode.get_id());
this.gnode.delete();
this.pool.delete();
Expand Down
26 changes: 0 additions & 26 deletions packages/perspective/test/html/benchmark.html

This file was deleted.

15 changes: 15 additions & 0 deletions packages/perspective/test/js/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,20 @@ module.exports = perspective => {
view.delete();
table.delete();
});

it("replace the rows in the table atomically", async function() {
const table = perspective.table([{x: 1, y: 2}, {x: 3, y: 4}]);
const view = table.view();
setTimeout(() => table.replace([{x: 5, y: 6}]));
let json = await view.to_json();
expect(json).toHaveLength(2);
expect(json).toEqual([{x: 1, y: 2}, {x: 3, y: 4}]);
await new Promise(setTimeout);
json = await view.to_json();
expect(json).toHaveLength(1);
expect(json).toEqual([{x: 5, y: 6}]);
view.delete();
table.delete();
});
});
};