Skip to content

Commit

Permalink
Removes explicit perspective-server webworker
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Stein <steinlink@gmail.com>
  • Loading branch information
texodus committed Sep 23, 2024
1 parent 0aa19d5 commit a9b9258
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 103 deletions.
12 changes: 11 additions & 1 deletion .github/actions/install-wheel/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@
name: "Install wheel"
description: "Installs the wheel depending on build platform, because Python"

inputs:
inplace:
default: "true"
description: "Install in-place?"

runs:
using: "composite"
steps:
- name: Install wheel (Linux)
shell: sh
run: python -m pip install -U --no-dependencies *.whl --target rust/perspective-python
if: ${{ runner.os == 'Linux' }}
if: ${{ inputs.inplace == 'true' && runner.os == 'Linux' }}

- name: Install wheel (Linux)
shell: sh
run: python -m pip install -U --no-dependencies *.whl
if: ${{ inputs.inplace != 'true' && runner.os == 'Linux' }}

- name: Install wheel (OSX)
shell: sh
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ jobs:
name: perspective-python-dist-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python-version }}

- uses: ./.github/actions/install-wheel
with:
inplace: "false"

- name: Benchmarks
run: pnpm run bench
Expand Down
10 changes: 5 additions & 5 deletions cpp/perspective/src/cpp/arrow_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,11 @@ csvToTable(
auto read_options = arrow::csv::ReadOptions::Defaults();
auto parse_options = arrow::csv::ParseOptions::Defaults();
auto convert_options = arrow::csv::ConvertOptions::Defaults();
#ifdef PSP_PARALLEL_FOR
read_options.use_threads = true;
#else
read_options.use_threads = false;
#endif
#ifdef PSP_PARALLEL_FOR
read_options.use_threads = true;
#else
read_options.use_threads = false;
#endif
parse_options.newlines_in_values = true;

if (is_update) {
Expand Down
10 changes: 5 additions & 5 deletions cpp/perspective/src/cpp/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,11 @@ View<CTX_T>::data_slice_to_arrow(
options.codec = std::move(codec).ValueUnsafe();
}

#ifdef PSP_PARALLEL_FOR
options.use_threads = true;
#else
options.use_threads = false;
#endif
#ifdef PSP_PARALLEL_FOR
options.use_threads = true;
#else
options.use_threads = false;
#endif

auto res = arrow::ipc::MakeStreamWriter(&sink, arrow_schema, options);
std::shared_ptr<arrow::ipc::RecordBatchWriter> writer = *res;
Expand Down
1 change: 0 additions & 1 deletion examples/blocks/src/editable/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<script type="module" src="/node_modules/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>

<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.js" as="fetch" type="application/javascript" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/superstore-arrow/superstore.lz4.arrow" as="fetch" type="arraybuffer" crossorigin="anonymous" />
Expand Down
1 change: 0 additions & 1 deletion examples/blocks/src/market/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<link rel="preload" href="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.js" as="fetch" type="application/javascript" crossorigin="anonymous" />
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>
Expand Down
1 change: 0 additions & 1 deletion examples/blocks/src/nypd/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<link rel="preload" href="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.js" as="script" type="application/javascript" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
<script type="module" src="/node_modules/@finos/perspective-workspace/dist/cdn/perspective-workspace.js"></script>
Expand Down
1 change: 0 additions & 1 deletion examples/blocks/src/raycasting/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.js" as="fetch" type="application/javascript" crossorigin="anonymous" />

<script type="module" src="index.js"></script>
<link rel="stylesheet" href="index.css" />
Expand Down
1 change: 0 additions & 1 deletion examples/blocks/src/webcam/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<link rel="preload" href="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.js" as="fetch" type="application/javascript" crossorigin="anonymous" />
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>
Expand Down
1 change: 0 additions & 1 deletion examples/esbuild-example/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<link rel="preload" href="perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="superstore.lz4.arrow" as="fetch" type="arraybuffer" crossorigin="anonymous" />
<link rel="preload" href="perspective-server.js" as="fetch" type="application/javascript" crossorigin="anonymous" />

<script type="module" src="index.js"></script>
<link rel="stylesheet" href="index.css" />
Expand Down
1 change: 0 additions & 1 deletion packages/perspective-esbuild-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ exports.PerspectiveEsbuildPlugin = function PerspectiveEsbuildPlugin(
) {
const wasm_plugin = WasmPlugin(!!options.wasm?.inline);
const worker_plugin = WorkerPlugin({
inline: !!options.worker?.inline,
targetdir: options.worker?.targetdir,
});

Expand Down
89 changes: 10 additions & 79 deletions packages/perspective-esbuild-plugin/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const path = require("path");
const esbuild = require("esbuild");

exports.WorkerPlugin = function WorkerPlugin(options = {}) {
const inline = !!options.inline;
const targetdir = options.targetdir || "build/worker";
function setup(build) {
const options = build.initialOptions;
Expand All @@ -34,16 +33,17 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {
const subbuild = esbuild.build({
target: ["es2021"],
entryPoints: [entryPoint],
outfile,
// outfile,
define: {
global: "self",
},
entryNames: "[name]",
chunkNames: "[name]",
assetNames: "[name]",
minify: !process.env.PSP_DEBUG,
minify: true,
bundle: true,
sourcemap: true,
sourcemap: false,
write: false,
});

return {
Expand All @@ -68,10 +68,9 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {
build.onLoad(
{ filter: /.*/, namespace: "worker-stub" },
async (args) => {
if (inline) {
return {
pluginData: args.pluginData,
contents: `
return {
pluginData: args.pluginData,
contents: `
import worker from ${JSON.stringify(args.path)};
function make_host(a, b) {
function addEventListener(type, callback) {
Expand Down Expand Up @@ -126,82 +125,14 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {
export default initialize;
`,
};
}

return {
pluginData: args.pluginData,
contents: `
import worker from ${JSON.stringify(args.path)};
async function get_worker_code() {
const url = new URL(__PSP_INLINE_WORKER__(worker), import.meta.url);
const req = await fetch(url);
const code = await req.text();
return code;
};
function make_host(a, b) {
function addEventListener(type, callback) {
a.push(callback);
}
function removeEventListener(callback) {
const idx = a.indexOf(callback);
if (idx > -1) {
a.splice(idx, 1);
}
}
function postMessage(msg) {
for (const listener of b) {
listener({data: msg});
}
}
return {
addEventListener,
removeEventListener,
postMessage,
location: {href: ""}
}
}
function run_single_threaded(code) {
let f = Function("const self = arguments[0];" + code);
const workers = [];
const mains = [];
f(make_host(workers, mains));
return make_host(mains, workers);
}
export const initialize = async function () {
const code = await get_worker_code();
if (window.location.protocol.startsWith("file") && !window.isElectron) {
console.warn("file:// protocol does not support Web Workers");
return run_single_threaded(code);
}
try {
const blob = new Blob([code], {type: 'application/javascript'});
const url = URL.createObjectURL(blob);
return new Worker(url, {type: "module"});
} catch (e) {
console.warn("Failed to instantiate worker, falling back to single-threaded runtime", e);
return run_single_threaded(code);
}
};
export default initialize;
`,
};
}
);

build.onLoad({ filter: /.*/, namespace: "worker" }, async (args) => {
// Get the subbuild output and delete the temp file
await args.pluginData.subbuild;
contents = await fs.promises.readFile(args.pluginData.outfile);

const result = await args.pluginData.subbuild;
const contents = result.outputFiles[0].contents;
// // Copy the sourcemaps also
// const mapfile = args.pluginData.outfile + ".map";
// sourcemap = await fs.promises.readFile(mapfile);
Expand All @@ -221,7 +152,7 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {

return {
contents,
loader: inline ? "text" : "file",
loader: "text",
};
});

Expand Down
1 change: 0 additions & 1 deletion rust/perspective-js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const BUILD = [
plugins: [
PerspectiveEsbuildPlugin({
wasm: { inline: true },
worker: { inline: true },
}),
],
outfile: "dist/esm/perspective.inline.js",
Expand Down
4 changes: 4 additions & 0 deletions rust/perspective-server/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ use base64::prelude::*;
use regex::{Captures, Regex};

fn main() -> Result<(), std::io::Error> {
if std::env::var("DOCS_RS").is_ok() {
return Ok(());
}

let markdown = fs::read_to_string("./docs/lib.md")?;
let markdown = Regex::new("<img src=\"(.+?)\"")
.expect("regex")
Expand Down
3 changes: 0 additions & 3 deletions rust/perspective-server/build/psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ pub fn cmake_build() -> Result<Option<PathBuf>, std::io::Error> {
);
}

if matches!(std::env::var("DOCS_RS").as_deref(), Ok("1")) {
return Ok(None);
}

let mut dst = Config::new("cpp/perspective");
if cfg!(windows) && std::option_env!("CI").is_some() {
Expand Down
2 changes: 0 additions & 2 deletions tools/perspective-bench/src/js/benchmark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,9 @@ async function benchmark_puppeteer_version(version, benchmarks_table) {
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.js" as="fetch" type="application/javascript" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective/dist/cdn/perspective-server.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.wasm" as="fetch" type="application/wasm" crossorigin="anonymous" />
<link rel="preload" href="/node_modules/superstore-arrow/superstore.lz4.arrow" as="fetch" type="arraybuffer" crossorigin="anonymous" />
</head>
</html>`);

Expand Down

0 comments on commit a9b9258

Please sign in to comment.