Web Workers
Bases can offload formula calculation to a Worker1 over RPC. Set notExecuteFormula: true on the main thread's formula engine, and register the remote Bases plugin and the calculating engine inside the Worker.
This page starts from installation and basic usage, and the snippets below extend that setup. Register plugins before creating or loading content, and replace an existing registration rather than registering the same plugin twice.
Main thread
UniverRPCMainThreadPlugin
workerURLstring | URL | WorkerConnects the editor to a Worker that performs formula calculation.
UniverProFormulaEnginePlugin
notExecuteFormulabooleanDefault:falseSkips formula calculation on the main thread when the Worker performs it.
import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'import { UniverRPCMainThreadPlugin } from '@univerjs/rpc'univer.registerPlugin(UniverRPCMainThreadPlugin, { workerURL: new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),})univer.registerPlugin(UniverProFormulaEnginePlugin, { notExecuteFormula: true })Worker entry
UniverLicensePlugin
licensestringContents of the client license file.
import { UniverRemoteBasesPlugin } from '@univerjs-pro/bases/worker'import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula/worker'import { UniverLicensePlugin } from '@univerjs-pro/license'import { LocaleType, Univer } from '@univerjs/core'import { UniverRPCWorkerThreadPlugin } from '@univerjs/rpc/worker'const univer = new Univer({ locale: LocaleType.EN_US })univer.registerPlugin(UniverLicensePlugin, { license: 'your license.txt' })univer.registerPlugin(UniverProFormulaEnginePlugin)univer.registerPlugin(UniverRemoteBasesPlugin)univer.registerPlugin(UniverRPCWorkerThreadPlugin)Use a module Worker with its own entry file, and keep package versions identical in the Worker and on the main thread. Rendering and user interaction remain on the main thread.
Pivot views and dashboards
To run dashboard pivot calculation in the Worker, set notExecuteCalculation: true on the main thread's UniverBaseDashboardPlugin and register UniverRemoteBaseDashboardPlugin in the same Worker. Dashboard UI plugins remain on the main thread.
UniverBaseDashboardPlugin
notExecuteCalculationbooleanMoves dashboard pivot calculation off the main thread. Set this option totruewhen using the remote dashboard plugin.
import { UniverBaseDashboardPlugin } from '@univerjs-pro/bases-dashboard'univer.registerPlugin(UniverBaseDashboardPlugin, { notExecuteCalculation: true })import { UniverRemoteBaseDashboardPlugin } from '@univerjs-pro/bases-dashboard/worker'univer.registerPlugin(UniverRemoteBaseDashboardPlugin)Footnotes
-
A Web Worker runs JavaScript outside the browser’s main thread and exchanges messages with it. It cannot access the page DOM directly; moving calculations into a Worker does not move the editor UI there. ↩
How is this guide?