# Performance Guide

Optimize Marked for your use case.

## Performance Characteristics

- **Non-blocking**: No I/O operations
- **No caching**: Each parse is independent
- **Memory efficient**: Tokens kept in memory during parsing only
- **Fast**: <10ms for 100KB documents (typical)

## Caching

```javascript { .api }
import { marked } from "marked";

const cache = new Map();

function cachedParse(markdown) {
  if (cache.has(markdown)) {
    return cache.get(markdown);
  }
  const html = marked.parse(markdown);
  cache.set(markdown, html);
  return html;
}
```

## Reuse Instances

```javascript { .api }
import { marked } from "marked";

const parser = new marked.Parser();
const renderer = new marked.Renderer();
parser.renderer = renderer;

// Parse multiple documents
const htmls = documents.map(doc => {
  const tokens = marked.lexer(doc);
  return parser.parse(tokens);
});
```

## Avoid Async Overhead

```javascript { .api }
// Only use async when needed
marked.setOptions({ async: false });  // Faster
```

## Profile Extensions

```javascript { .api }
console.time('parse-with-extension');
const html = marked.parse(markdown);
console.timeEnd('parse-with-extension');
```
