Skip to main content

Bundling

math.gl is published as tree-shakeable ES modules. Application bundle size depends on the APIs imported, the methods used, the bundler configuration, and the compression applied by the server.

Always assess math.gl's impact using a minified production build of the actual application. The installed package size, TypeScript source size, and development bundles are not useful estimates of the bytes delivered to users.

Importing core classes

Use named imports from @math.gl/core:

import {Matrix4, Vector3} from '@math.gl/core';

Modern production bundlers can then remove unused classes and methods. Avoid retaining the complete package namespace in application state or passing it through APIs, since that can make every export observable and prevent tree-shaking.

The low-level gl-matrix-compatible functions are intentionally separate from the root entry point in v5. Import only the module needed by the application:

import * as mat4 from '@math.gl/core/mat4';
import * as vec3 from '@math.gl/core/vec3';

Available low-level subpaths are /mat3, /mat4, /quat, /vec2, /vec3, and /vec4.

Core class bundle sizes

The following v5 reference measurements use esbuild 0.28.1 with minification and tree-shaking enabled, ES module output, and browser targets Chrome 110, Firefox 110, and Safari 15. Transfer sizes use gzip level 9 and Brotli quality 11. Values are decimal KB, where 1 KB is 1,000 bytes.

Each named-import fixture constructs one instance from the public @math.gl/core entry point. The full public-entry fixture retains every root runtime export. These are stable comparison fixtures, not predictions for every application bundle.

v5 fixtureMinifiedgzipBrotli
Vector25.75 KB1.82 KB1.63 KB
Vector37.45 KB2.39 KB2.12 KB
Vector46.08 KB2.08 KB1.84 KB
Matrix37.83 KB2.79 KB2.40 KB
Matrix415.73 KB5.42 KB4.43 KB
Quaternion8.60 KB2.92 KB2.60 KB
Euler7.97 KB2.69 KB2.38 KB
SphericalCoordinates3.00 KB1.26 KB1.16 KB
Pose26.10 KB8.05 KB6.68 KB
Full public entry41.62 KB11.90 KB9.96 KB

Pose intentionally composes several lower-level classes, so it retains more code than a single vector or rotation representation. Applications that only need one representation should import that class directly.

v5 improvements

Compared with the same fixtures built from math.gl v4.1.0, every measured core class is smaller. The largest reductions come from removing deprecated root namespaces, making conversions destination-owned, and replacing runtime peer-class dependencies with structural types and direct calculations.

Fixturev4.1 gzipv5 gzipReduction
Vector22.06 KB1.82 KB12%
Vector32.63 KB2.39 KB9%
Vector42.32 KB2.08 KB10%
Matrix33.08 KB2.79 KB9%
Matrix45.75 KB5.42 KB6%
Quaternion4.10 KB2.92 KB29%
Euler5.67 KB2.69 KB53%
SphericalCoordinates3.29 KB1.26 KB62%
Pose10.39 KB8.05 KB23%
Full public entry18.96 KB11.90 KB37%

In particular, SphericalCoordinates now accepts the structural Vector3Like type and performs its conversions directly. It no longer imports the Vector3 class or the low-level vec3 namespace at runtime.

Interpreting bundle numbers

  • Minified size is useful for attributing code and comparing implementation changes.
  • gzip approximates transfer size when a server uses gzip compression.
  • Brotli is often smaller for static assets and is worth enabling in production.
  • Source maps are excluded and should normally be delivered only when requested by developer tooling.
  • Different bundlers, targets, minifiers, dependency versions, and chunk boundaries produce different results. Treat the values above as regression references rather than universal costs.

Tree-shaking operates on the complete application graph. A source file that looks large on disk may add little when only one export is reachable, while a small static import can retain a larger class hierarchy. Compare production bundle analyzer output before and after changing imports.