BunPress Documentation

Performance Optimization

On this page 45

BunPress is built for speed. This guide covers optimization techniques for even better performance.

Build Performance

Parallel Processing

BunPress builds pages in parallel by default:

export default {
  build: {
    parallel: true,
    workers: 4, // Number of worker threads
  },
}

Incremental Builds

Only rebuild changed files:

bunpress build --incremental

Asset Optimization

Image Optimization

export default {
  build: {
    images: {
      optimize: true,
      formats: ['webp', 'avif'],
      quality: 80,
      lazy: true,
    },
  },
}

CSS Optimization

export default {
  build: {
    css: {
      minify: true,
      purge: true, // Remove unused CSS
      inline: true, // Inline critical CSS
    },
  },
}

JavaScript Optimization

export default {
  build: {
    js: {
      minify: true,
      treeshake: true,
      split: true, // Code splitting
    },
  },
}

Content Optimization

Markdown Caching

export default {
  markdown: {
    cache: true,
  },
}

Syntax Highlighting

Preload common languages:

export default {
  markdown: {
    syntaxHighlighting: {
      preloadLanguages: ['typescript', 'javascript', 'bash'],
      lazy: true, // Lazy load other languages
    },
  },
}

Search Index

Build search index at build time:

export default {
  search: {
    prebuilt: true,
    lazy: true, // Load on demand
  },
}

CDN and Caching

Static Assets

export default {
  build: {
    assets: {
      hash: true, // Add content hash to filenames
      maxAge: 31536000, // 1 year cache
    },
  },
}

CDN Configuration

export default {
  build: {
    base: 'https://cdn.example.com/',
    assetPrefix: 'https://cdn.example.com/assets/',
  },
}

Compression

Gzip/Brotli

export default {
  build: {
    compress: {
      gzip: true,
      brotli: true,
    },
  },
}

Pre-compress Assets

bunpress build --compress

Benchmarking

Markdown Engine Performance

BunPress uses Bun's built-in Zig-based markdown parser (Bun.markdown), which is significantly faster than all JavaScript-based alternatives. All engines are configured with equivalent GFM features (tables, strikethrough, task lists, autolinks) for a fair comparison. These results were measured on Apple M3 Pro, 18GB RAM, Bun 1.3.10, using mitata.

Fairness note: These results are conservative. Real VitePress adds Shiki syntax highlighting + Vue plugins (@mdit-vue/plugin-headers, @mdit-vue/plugin-sfc, @mdit-vue/plugin-component) on top of markdown-it. Real Astro adds Shiki on top of remark/rehype. commonmark.js does not support GFM (no tables, strikethrough, or task lists), so it processes fewer features and appears artificially fast.

Engines tested:

  • BunPress - Bun.markdown (Zig-based, built into Bun) with full GFM
  • VitePress - markdown-it + task-lists plugin (JS, as configured in VitePress)
  • Eleventy - markdown-it + task-lists plugin (JS, default engine + GFM parity)
  • Astro - remark + remark-gfm + rehype (JS, unified ecosystem)
  • marked - JS, fast compiler (GFM enabled by default)
  • micromark - JS, small + safe + CommonMark (with GFM extension)
  • showdown - JS, bidirectional converter (with GFM options)
  • commonmark (no GFM) - JS, reference CommonMark impl (NO GFM support)

Simple Markdown (paragraph + inline formatting)

EngineAvg Timevs BunPress
BunPress2.09 µs-
commonmark (no GFM)3.91 µs1.9x slower
Eleventy4.93 µs2.4x slower
VitePress7.87 µs3.8x slower
marked29.67 µs14x slower
showdown32.48 µs16x slower
micromark120.10 µs57x slower
Astro126.36 µs60x slower

Inline-Heavy Content (~3KB)

EngineAvg Timevs BunPress
BunPress22.09 µs-
commonmark (no GFM)79.92 µs3.6x slower
Eleventy119.70 µs5.4x slower
VitePress174.47 µs7.9x slower
showdown489.20 µs22x slower
marked1.57 ms71x slower
micromark1.70 ms77x slower
Astro2.26 ms102x slower

Headings

EngineAvg Timevs BunPress
BunPress6.14 µs-
Eleventy22.28 µs3.6x slower
commonmark (no GFM)24.62 µs4x slower
VitePress30.52 µs5x slower
marked54.01 µs8.8x slower
showdown160.55 µs26x slower
micromark543.45 µs89x slower
Astro634.46 µs103x slower

Lists (unordered, ordered, task lists)

EngineAvg Timevs BunPress
BunPress15.32 µs-
Eleventy68.88 µs4.5x slower
commonmark (no GFM)83.98 µs5.5x slower
VitePress90.52 µs5.9x slower
marked562.89 µs37x slower
showdown767.39 µs50x slower
micromark1.66 ms108x slower
Astro2.10 ms137x slower

GFM Tables

EngineAvg Timevs BunPress
BunPress27.03 µs-
commonmark (no GFM)32.99 µs1.2x slower
Eleventy142.51 µs5.3x slower
VitePress182.55 µs6.8x slower
marked525.06 µs19x slower
showdown685.48 µs25x slower
micromark3.36 ms124x slower
Astro4.26 ms158x slower

Code Blocks

EngineAvg Timevs BunPress
BunPress19.16 µs-
Eleventy31.85 µs1.7x slower
marked33.58 µs1.8x slower
VitePress34.66 µs1.8x slower
commonmark (no GFM)37.47 µs2x slower
showdown149.52 µs7.8x slower
micromark774.78 µs40x slower
Astro825.23 µs43x slower

Mixed Content (realistic doc page)

EngineAvg Timevs BunPress
BunPress7.92 µs-
commonmark (no GFM)34.69 µs4.4x slower
Eleventy37.16 µs4.7x slower
VitePress48.82 µs6.2x slower
marked178.76 µs23x slower
showdown247.80 µs31x slower
micromark743.17 µs94x slower
Astro878.50 µs111x slower

Real-World Doc Page (~3KB markdown)

EngineAvg Timevs BunPress
BunPress28.60 µs-
commonmark (no GFM)101.47 µs3.5x slower
Eleventy124.67 µs4.4x slower
VitePress178.68 µs6.2x slower
showdown791.29 µs28x slower
marked841.17 µs29x slower
micromark2.03 ms71x slower
Astro2.56 ms90x slower

Large Document Stress Test (~33KB markdown)

EngineAvg Timevs BunPress
BunPress204.97 µs-
commonmark (no GFM)1.01 ms4.9x slower
Eleventy1.07 ms5.2x slower
VitePress1.40 ms6.8x slower
showdown12.76 ms62x slower
micromark21.61 ms105x slower
Astro26.56 ms130x slower
marked47.41 ms231x slower

Throughput: 100 Mixed Documents

EngineAvg Timevs BunPress
BunPress827.40 µs-
commonmark (no GFM)3.45 ms4.2x slower
Eleventy3.80 ms4.6x slower
VitePress4.85 ms5.9x slower
marked17.43 ms21x slower
showdown25.29 ms31x slower
micromark72.79 ms88x slower
Astro84.95 ms103x slower

Build Performance (4,000 markdown files)

Using the same methodology as 11ty's official performance tests:

GeneratorBuild TimeFiles/Secondvs BunPress
BunPress0.18s22,714-
Eleventy1.93s2,07311x slower
VitePress8.50s47147x slower
Astro22.90s175130x slower
Gatsby29.05s138165x slower
Next.js70.65s57401x slower
GeneratorBuild Timevs BunPress
BunPress4.12s-
VitePress8.50s2x slower
Astro22.90s5.6x slower
Gatsby29.05s7x slower
Next.js70.65s17x slower

Running Benchmarks

# Markdown engine benchmarks (self-contained)
cd benchmark && bun install && bun run bench

# All benchmarks (build, server, features)
cd benchmark && bun run bench:all

Build Time

bunpress build --profile

Page Speed

bunpress analyze

Monitoring

Build Stats

export default {
  build: {
    stats: true,
    statsFile: './build-stats.json',
  },
}

Bundle Analysis

bunpress build --analyze

Best Practices

Optimize Images

  1. Use WebP/AVIF formats
  2. Specify dimensions
  3. Use lazy loading
  4. Responsive images
![Alt text](/image.webp){width=800 height=600 loading=lazy}

Minimize JavaScript

  1. Defer non-critical scripts
  2. Use async loading
  3. Tree-shake unused code
  4. Split by route

Optimize CSS

  1. Purge unused styles
  2. Inline critical CSS
  3. Defer non-critical CSS
  4. Minify in production

Content Best Practices

  1. Keep pages focused
  2. Lazy load heavy content
  3. Use appropriate heading levels
  4. Optimize code examples

Performance Checklist

  • Enable build caching
  • Optimize images
  • Minify CSS/JS
  • Enable compression
  • Configure CDN
  • Preload critical assets
  • Lazy load non-critical content
  • Enable prefetching
  • Monitor build times
  • Analyze bundle size

Lighthouse Score

Target scores:

MetricTarget
Performance95+
Accessibility100
Best Practices100
SEO100