diff --git a/.github/workflows/library-web.yml b/.github/workflows/library-web.yml index 39eb0dfa..fecc6d92 100644 --- a/.github/workflows/library-web.yml +++ b/.github/workflows/library-web.yml @@ -17,7 +17,7 @@ on: webgl: required: true type: boolean - multithreading: + multithreaded: required: true type: boolean @@ -34,7 +34,7 @@ jobs: just nightly-toolchain just nightly-targets wasm32-unknown-unknown - name: Install rust sources (build-std) - if: inputs.multithreading + if: inputs.multithreaded shell: bash run: | just nightly-install-src @@ -46,7 +46,7 @@ jobs: - uses: Swatinem/rust-cache@v1 - name: Build lib shell: bash - run: just web-lib build --release ${{ inputs.webgl && '--webgl' || '' }} ${{ inputs.multithreading && '--multithreading' || '' }} + run: just web-lib build --release ${{ inputs.webgl && '--webgl' || '' }} ${{ inputs.multithreaded && '--multithreaded' || '' }} - name: Build demo shell: bash run: just web-demo build @@ -73,7 +73,7 @@ jobs: name: ${{ inputs.name }} path: demo - name: Set HTTP Headers for Cloudflare - if: inputs.multithreading + if: inputs.multithreaded shell: bash run: | echo "/* diff --git a/.github/workflows/on_pull_request.yml b/.github/workflows/on_pull_request.yml index 6bfb3063..829f72f9 100644 --- a/.github/workflows/on_pull_request.yml +++ b/.github/workflows/on_pull_request.yml @@ -24,14 +24,14 @@ jobs: with: name: maplibre-rs-demo-webgl webgl: true - multithreading: false + multithreaded: false deploy: true library-web-webgpu: uses: ./.github/workflows/library-web.yml with: name: maplibre-rs-demo-webgpu webgl: false - multithreading: false + multithreaded: false deploy: true library-apple: uses: ./.github/workflows/library-apple.yml diff --git a/web/lib/build.mjs b/web/lib/build.mjs index 97bb0c95..639d86fd 100644 --- a/web/lib/build.mjs +++ b/web/lib/build.mjs @@ -136,7 +136,8 @@ const wasmPack = () => { "-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", # Enables the possibility to import memory into wasm. # Without --shared-memory it is not possible to use shared WebAssembly.Memory. - "-C", "link-args=--shared-memory --import-memory", + # Set maximum memory to 200MB + "-C", "link-args=--shared-memory --import-memory --max-memory=209715200" ]` let cargo = spawnSync('cargo', [ diff --git a/web/lib/src/index.ts b/web/lib/src/index.ts index 5617be4c..08c452b7 100644 --- a/web/lib/src/index.ts +++ b/web/lib/src/index.ts @@ -3,9 +3,9 @@ import {Spector} from "spectorjs" import {checkRequirements, checkWasmFeatures} from "./browser"; import {preventDefaultTouchActions} from "./canvas"; // @ts-ignore esbuild plugin is handling this -import MultithreadedPoolWorker from './sync/multithreaded-pool.worker.js'; +import MultithreadedPoolWorker from './multithreaded/multithreaded-pool.worker.js'; // @ts-ignore esbuild plugin is handling this -import PoolWorker from './unsync/pool.worker.js'; +import PoolWorker from './singlethreaded/pool.worker.js'; export const startMapLibre = async (wasmPath: string | undefined, workerPath: string | undefined) => { await checkWasmFeatures() @@ -58,7 +58,7 @@ export const startMapLibre = async (wasmPath: string | undefined, workerPath: st callback[0] = (message) => { // @ts-ignore TODO unsync_main_entry may not be defined - maplibre.unsync_main_entry(clonedMap, message.data[0], new Uint8Array(message.data[1])) + maplibre.singlethreaded_main_entry(clonedMap, message.data[0], new Uint8Array(message.data[1])) } await maplibre.run(map) diff --git a/web/lib/src/sync/multithreaded-pool.worker.ts b/web/lib/src/multithreaded/multithreaded-pool.worker.ts similarity index 90% rename from web/lib/src/sync/multithreaded-pool.worker.ts rename to web/lib/src/multithreaded/multithreaded-pool.worker.ts index 910c83d7..90659348 100644 --- a/web/lib/src/sync/multithreaded-pool.worker.ts +++ b/web/lib/src/multithreaded/multithreaded-pool.worker.ts @@ -14,6 +14,6 @@ onmessage = async message => { // This will queue further commands up until the module is fully initialised: await initialised; // @ts-ignore TODO may not exist - await maplibre.sync_worker_entry(message.data); + await maplibre.multithreaded_worker_entry(message.data); }; } diff --git a/web/lib/src/unsync/pool.worker.ts b/web/lib/src/singlethreaded/pool.worker.ts similarity index 90% rename from web/lib/src/unsync/pool.worker.ts rename to web/lib/src/singlethreaded/pool.worker.ts index 6a4abd87..e08cf102 100644 --- a/web/lib/src/unsync/pool.worker.ts +++ b/web/lib/src/singlethreaded/pool.worker.ts @@ -18,6 +18,6 @@ onmessage = async message => { let procedure_ptr = message.data[0]; let input = message.data[1]; // @ts-ignore TODO - await maplibre.unsync_worker_entry(procedure_ptr, input); + await maplibre.singlethreaded_worker_entry(procedure_ptr, input); }; } diff --git a/web/src/lib.rs b/web/src/lib.rs index 5b045123..ea58c536 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -43,20 +43,20 @@ pub type MapType = Map< WinitEnvironment< NopScheduler, WHATWGFetchHttpClient, - platform::unsync::transferables::LinearTransferables, - platform::unsync::apc::PassingAsyncProcedureCall, + platform::singlethreaded::transferables::LinearTransferables, + platform::singlethreaded::apc::PassingAsyncProcedureCall, >, >; #[cfg(target_feature = "atomics")] pub type MapType = Map< WinitEnvironment< - platform::sync::pool_scheduler::WebWorkerPoolScheduler, + platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler, WHATWGFetchHttpClient, maplibre::io::transferables::DefaultTransferables, maplibre::io::apc::SchedulerAsyncProcedureCall< WHATWGFetchHttpClient, - platform::sync::pool_scheduler::WebWorkerPoolScheduler, + platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler, >, >, >; @@ -73,19 +73,19 @@ pub async fn create_map(new_worker: js_sys::Function) -> u32 { builder = builder .with_apc(maplibre::io::apc::SchedulerAsyncProcedureCall::new( WHATWGFetchHttpClient::new(), - platform::sync::pool_scheduler::WebWorkerPoolScheduler::new(new_worker.clone()), + platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler::new( + new_worker.clone(), + ), )) - .with_scheduler(platform::sync::pool_scheduler::WebWorkerPoolScheduler::new( - new_worker, - )); + .with_scheduler( + platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler::new(new_worker), + ); } #[cfg(not(target_feature = "atomics"))] { builder = builder - .with_apc(platform::unsync::apc::PassingAsyncProcedureCall::new( - new_worker, 4, - )) + .with_apc(platform::singlethreaded::apc::PassingAsyncProcedureCall::new(new_worker, 4)) .with_scheduler(NopScheduler); } diff --git a/web/src/platform/mod.rs b/web/src/platform/mod.rs index ed20f0e6..c9fe5bc2 100644 --- a/web/src/platform/mod.rs +++ b/web/src/platform/mod.rs @@ -4,7 +4,7 @@ use maplibre::error::Error; pub mod http_client; #[cfg(target_feature = "atomics")] -pub mod sync; +pub mod multithreaded; #[cfg(not(target_feature = "atomics"))] -pub mod unsync; +pub mod singlethreaded; diff --git a/web/src/platform/sync/mod.rs b/web/src/platform/multithreaded/mod.rs similarity index 100% rename from web/src/platform/sync/mod.rs rename to web/src/platform/multithreaded/mod.rs diff --git a/web/src/platform/sync/pool.rs b/web/src/platform/multithreaded/pool.rs similarity index 98% rename from web/src/platform/sync/pool.rs rename to web/src/platform/multithreaded/pool.rs index abe23392..2b459b19 100644 --- a/web/src/platform/sync/pool.rs +++ b/web/src/platform/multithreaded/pool.rs @@ -146,7 +146,7 @@ impl PoolState { /// Entry point invoked by the worker. #[wasm_bindgen] -pub async fn sync_worker_entry(ptr: u32) -> Result<(), JsValue> { +pub async fn multithreaded_worker_entry(ptr: u32) -> Result<(), JsValue> { let ptr = unsafe { Box::from_raw(ptr as *mut Work) }; JsFuture::from((ptr.func)()).await?; Ok(()) diff --git a/web/src/platform/sync/pool_scheduler.rs b/web/src/platform/multithreaded/pool_scheduler.rs similarity index 100% rename from web/src/platform/sync/pool_scheduler.rs rename to web/src/platform/multithreaded/pool_scheduler.rs diff --git a/web/src/platform/unsync/apc.rs b/web/src/platform/singlethreaded/apc.rs similarity index 95% rename from web/src/platform/unsync/apc.rs rename to web/src/platform/singlethreaded/apc.rs index b631263b..e299724f 100644 --- a/web/src/platform/unsync/apc.rs +++ b/web/src/platform/singlethreaded/apc.rs @@ -28,7 +28,9 @@ use wasm_bindgen::{prelude::*, JsCast, JsValue}; use web_sys::{DedicatedWorkerGlobalScope, Worker}; use crate::{ - platform::unsync::transferables::{InnerData, LinearTessellatedLayer, LinearTransferables}, + platform::singlethreaded::transferables::{ + InnerData, LinearTessellatedLayer, LinearTransferables, + }, MapType, WHATWGFetchHttpClient, }; @@ -124,9 +126,7 @@ impl AsyncProcedureCall for PassingAsyncProce /// Entry point invoked by the worker. #[wasm_bindgen] -pub async fn unsync_worker_entry(procedure_ptr: u32, input: String) -> Result<(), JsValue> { - log::info!("worker_entry unsync"); - +pub async fn singlethreaded_worker_entry(procedure_ptr: u32, input: String) -> Result<(), JsValue> { let procedure: AsyncProcedure = unsafe { std::mem::transmute(procedure_ptr) }; let input = serde_json::from_str::(&input).unwrap(); // FIXME (wasm-executor): Remove unwrap @@ -142,7 +142,7 @@ pub async fn unsync_worker_entry(procedure_ptr: u32, input: String) -> Result<() /// Entry point invoked by the main thread. #[wasm_bindgen] -pub fn unsync_main_entry( +pub fn singlethreaded_main_entry( map_ptr: *const RefCell, tag: u32, data: Uint8Array, diff --git a/web/src/platform/unsync/mod.rs b/web/src/platform/singlethreaded/mod.rs similarity index 100% rename from web/src/platform/unsync/mod.rs rename to web/src/platform/singlethreaded/mod.rs diff --git a/web/src/platform/unsync/transferables.rs b/web/src/platform/singlethreaded/transferables.rs similarity index 100% rename from web/src/platform/unsync/transferables.rs rename to web/src/platform/singlethreaded/transferables.rs