API
@pbroom/color-kit/compute
Schedule plane compute on the JS backend, with telemetry.
26 exports10 values16 types
@pbroom/color-kit/compute runs batches of plane queries and returns the results
packed into typed arrays, ready to post from a worker without copying. Use
it when queries are heavy or frequent enough to leave the main thread, or
when you want timing telemetry about them.
Domains
- Running.
runPlaneComputetakes a plane, a list of queries and an optional trace request, and returns packed results with compute and marshal times.runPackedPlaneQueriesreturns only the packed results. Both run synchronously on the calling thread. - Packing.
packPlaneQueryResultsandunpackPlaneQueryResultsconvert between query results and the packed layout;getPackedPlaneQueryTransferableslists the buffers to transfer. - Scheduling and telemetry.
createPlaneComputeSchedulerroutes requests to a backend and records timings;runScheduledPlaneComputeuses a shared scheduler whose snapshotgetDefaultPlaneComputeTelemetrySnapshotreads. The built-in backend is JavaScript (createJsPlaneComputeBackend).
import { parse } from '@pbroom/color-kit';
import {
getPackedPlaneQueryTransferables,
runPlaneCompute,
} from '@pbroom/color-kit/compute';
const { result } = runPlaneCompute({
plane: { model: 'oklch', fixed: { h: 250 } },
queries: [
{ kind: 'gamutRegion', gamut: 'srgb' },
{ kind: 'contrastRegion', reference: parse('#fff'), level: 'AA' },
],
});
result.queryDescriptors.map((query) => query.kind);
// → ['gamutRegion', 'contrastRegion']
self.postMessage(result, {
transfer: getPackedPlaneQueryTransferables(result),
});On the main thread, unpackPlaneQueryResults(result) restores the query
results.
Scheduling
- function
createJsPlaneComputeBackendCreates a backend that solves plane queries in JavaScript on the calling thread and packs the results. - function
createPlaneComputeSchedulerCreates a plane compute scheduler that runs requests on the JS backend and records per-workload timing telemetry (EWMA of total time, bucketed by query kinds, workload signature, priority, quality, profile, and estimated budget). - function
runScheduledPlaneComputeRuns a batch of plane queries through a scheduler, which records timing telemetry and adds routing details to the response. - function
runPackedPlaneQueriesRuns a batch of plane queries and returns only the packed results. - function
runPlaneComputeRuns a batch of plane queries on a backend and returns packed results with timings. - function
getDefaultPlaneComputeTelemetrySnapshotReturns a copy of the shared default scheduler's telemetry, recorded by runScheduledPlaneCompute calls that use the default scheduler. - function
resetDefaultPlaneComputeTelemetryClears all telemetry held by the shared default scheduler.
Packing
- function
getPackedPlaneQueryTransferablesReturns the four ArrayBuffers backing a packed result, for zero-copy postMessage transfer. - function
packPlaneQueryResultsPacks plane query results into transfer-friendly typed arrays. - function
unpackPlaneQueryResultsDecodes a packed plane query payload back into query results. - interface
PackedPlaneQueryResultTransfer-friendly packed representation of batched plane query output. - type
PackedPlaneQueryDescriptorPer-query metadata in a packed result.
Types
- interface
PlaneComputeBackendSomething that can execute plane compute requests synchronously. - interface
PlaneComputeRequestA batch of plane queries to run against one plane. - interface
PlaneComputeResponseOutput of running a PlaneComputeRequest. - interface
PlaneComputeSchedulerRoutes compute requests to a backend and records timing telemetry. - type
PlaneComputeBackendKindCompute backends that exist today. - interface
PlaneComputeDebugTraceTraces for a traced compute request. - type
PlaneComputePerformanceProfileCaller's performance/quality trade-off profile. - type
PlaneComputePriorityCaller's urgency hint: 'drag' for interactive updates, 'idle' for settled renders. - type
PlaneComputeQualityCaller's requested quality tier. - interface
PlaneComputeScheduleTraceHow a scheduler routed one request. - interface
PlaneComputeSchedulerOptionsTelemetry settings for createPlaneComputeScheduler. - interface
PlaneComputeTelemetryBackendStatsTiming statistics for one backend within a telemetry bucket. "Total" time is computeTimeMs + marshalTimeMs of a run. - interface
PlaneComputeTelemetryBucketTelemetry for one workload shape: all scheduled requests whose schedule.bucketKey matches. - interface
PlaneComputeTelemetrySnapshotPoint-in-time copy of a scheduler's telemetry.