Skip to main content
RFC Status: This document is part of the OpenDocs RFC and subject to change based on community feedback.

Performance Optimization

Optimize your OpenDocs implementation to handle large codebases efficiently. This guide covers memory management, streaming, caching, and performance best practices.

Memory Management

Streaming Large Datasets with JSON $ref

For large codebases, avoid loading all DocItems into memory at once by using JSON $ref to external files:

Memory-Efficient Extraction

Process files one at a time instead of loading the entire project:

Batch Processing

Process items in batches for better performance:

Caching Strategies

LRU Cache for DocItems

File-Based Cache

For very large projects, use file-based caching:

Cache with TTL

Add time-to-live to cache entries:

Parallel Processing

Worker Threads for Extraction

Use worker threads to parallelize extraction:

Worker Thread Implementation

Performance Monitoring

Measure Extraction Performance

Optimization Tips

1. Use Incremental Extraction

Only re-extract changed files:

2. Lazy Load Child Items

Don’t extract all members upfront:

3. Optimize JSON with External References

Use JSON $ref to external files for large outputs instead of streaming JSONL:
Format Evolution: The format property in OpenDocs configurations enables future format support. While JSON $ref is currently recommended for large datasets, JSONL (line-delimited JSON) is being considered as an additional format option. JSONL would provide similar streaming performance benefits but with a single-file approach, making it suitable for different use cases and tooling preferences.

4. Profile Your Code

Use Node.js profiling tools:

Benchmarking

Create Performance Tests

See Also


This guide is part of the OpenDocs Specification RFC. Help us improve it by sharing your optimization techniques.