All skills
mapbox avatar

/mapbox-web-performance-patterns

@f5ae7de official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Performance optimization patterns for Mapbox GL JS web applications. Covers initialization waterfalls, bundle size, rendering performance, memory management, and web optimization. Prioritized by impact on user experience.

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-web-performance-patterns

This session only. Nothing lands on disk.

referencesmobile.md

≈587 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Mobile Performance

Problem: Mobile devices have limited resources (CPU, GPU, memory, battery).

Mobile-Specific Optimizations

// Detect mobile device
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);

const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v12',

  // Mobile optimizations
  ...(isMobile && {
    // Limit max zoom to reduce tile fetching at extreme zoom levels
    maxZoom: 18,

    // fadeDuration controls symbol collision fade animation only
    // Reducing it makes label transitions snappier
    fadeDuration: 0
  })
});

// Load simpler layers on mobile
map.on('load', () => {
  if (isMobile) {
    // Circle layers are cheaper than symbol layers (no collision detection,
    // no texture atlas, no text shaping)
    map.addLayer({
      id: 'markers-mobile',
      type: 'circle',
      source: 'data',
      paint: {
        'circle-radius': 8,
        'circle-color': '#007cbf'
      }
    });
  } else {
    // Rich desktop rendering with icons and labels
    map.addLayer({
      id: 'markers-desktop',
      type: 'symbol',
      source: 'data',
      layout: {
        'icon-image': 'marker',
        'icon-size': 1,
        'text-field': ['get', 'name'],
        'text-size': 12,
        'text-offset': [0, 1.5]
      }
    });
  }
});

Touch Interaction Optimization

// ✅ Simplify touch gestures
map.touchZoomRotate.disableRotation(); // Disable rotation (simpler gestures, fewer accidental rotations)

// Debounce expensive operations during touch
let touchTimeout;
map.on('touchmove', () => {
  if (touchTimeout) clearTimeout(touchTimeout);
  touchTimeout = setTimeout(() => {
    updateVisibleData();
  }, 500); // Wait for touch to settle
});

Performance-Sensitive Constructor Options

// These options have real GPU/performance costs -- only enable when needed
const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v12',

  // Default false -- only set true if you need map.getCanvas().toDataURL()
  // Costs: prevents GPU buffer optimization
  preserveDrawingBuffer: false,

  // Default false -- only set true if you need smooth diagonal lines
  // Costs: enables MSAA which increases GPU memory and fill cost
  antialias: false
});

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides a comprehensive set of performance optimization patterns and documentation for Mapbox GL JS applications. It focuses on legitimate development practices such as parallel data loading, bundle size optimization, and efficient marker rendering. No security risks or malicious patterns were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    1/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f5ae7de. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 hours ago.

Activeupdated 2 months ago
  • Performance
  • mapbox
  • web
  • rendering
  • bundle-size
  • markers
  • geojson
  • memory
  • optimization

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-web-performance-patterns

Provides performance optimization patterns for Mapbox GL JS applications, covering initialization waterfalls, bundle size, marker rendering, and memory management. Addresses critical issues like parallel data loading, symbol layers for large feature sets, and clustering strategies, with actionable code examples and performance thresholds.

Generated from the current SKILL.md.

Does this skill cover Mapbox GL JS only, or other Mapbox libraries?
This skill focuses on Mapbox GL JS web applications. It does not cover native mobile SDKs or server-side optimization.
What are the main performance bottlenecks this skill addresses?
The skill prioritizes initialization waterfalls (sequential data loading), bundle size, marker rendering (HTML vs symbol layers), and memory management. It covers the most impactful issues first, then optional optimizations.
When should I switch from HTML markers to symbol layers?
Use HTML markers for fewer than 100 markers. Switch to GPU-accelerated symbol layers for 100-10,000 markers, and add clustering for 10,000+ markers.
Does this skill provide code examples?
Yes. The skill includes concrete before/after code examples for initialization waterfalls, bundle optimization, marker strategies, and clustering patterns.

Generated from the current SKILL.md. These answers refresh after source changes.