Skip to content

Djot-PHP Performance Summary

Performance benchmarks for djot-php compared to other implementations.

Test Environment:

  • PHP 8.4.18 (OPcache enabled)
  • Node.js v18.19.1
  • Python 3.12.3
  • Rust (jotdown 0.7)
  • Go (godjot)
  • Linux 6.17.0-19-generic

Quick Reference

Document SizePHP FullThroughput
1 KB0.55 ms~2.0 MB/s
10 KB4.9 ms~2.2 MB/s
56 KB23 ms~2.4 MB/s
225 KB115 ms~1.9 MB/s
1 MB579 ms~1.9 MB/s

PHP Alternatives Comparison

With equivalent features enabled (tables, footnotes, smart typography):

Library30KB DocThroughputvs djot-php
erusev/parsedown1.69 ms16.0 MB/s6.7x faster
michelf/php-markdown5.16 ms5.2 MB/s2.2x faster
michelf/php-markdown (Extra)6.15 ms4.4 MB/s1.9x faster
djot-php11.36 ms2.6 MB/sbaseline
league/commonmark (GFM)15.00 ms1.8 MB/s1.3x slower
league/commonmark15.31 ms1.8 MB/s1.4x slower
league/commonmark (Full)23.54 ms1.3 MB/s2.1x slower

Key finding: djot-php is 2x faster than CommonMark when both have equivalent features (tables, footnotes, smart punct) enabled.

Cross-Language Comparison

Benchmarked on medium-sized documents (~56 KB):

ImplementationMean TimeThroughputvs PHP
Rust (jotdown)~1-2 ms~30+ MB/s~12x faster
Go (godjot)~2-4 ms~15+ MB/s~6x faster
JS (@djot/djot)8.1 ms5.2 MB/s2.8x faster
PHP (djot-php)23 ms2.4 MB/sbaseline
Python-Markdown*41.1 ms1.0 MB/s1.8x slower

*Python libraries are Markdown parsers (no Djot implementation exists for Python).

Document Size Scaling

PHP djot-php scales linearly with document size:

SizeInputMean TimeThroughput
tiny1.1 KB0.55 ms2.0 MB/s
small11.1 KB4.88 ms2.2 MB/s
medium56.1 KB23.24 ms2.4 MB/s
large225.5 KB114.52 ms1.9 MB/s
huge1.1 MB579.20 ms1.9 MB/s

Content Type Performance

Different content types have varying performance characteristics:

Content TypeSizeMean TimeThroughputNotes
code_heavy5.8 KB1.18 ms4.8 MB/sFastest - simple parsing
nested_lists5.6 KB3.48 ms1.6 MB/sAverage
complex8.9 KB6.18 ms1.4 MB/sMany features
tables9.2 KB6.67 ms1.3 MB/sTable parsing overhead
inline_heavy14.8 KB11.25 ms1.3 MB/sMany inline elements

Code-heavy documents are fastest because code blocks require minimal parsing.

Profile Performance

Different profiles have similar performance since they filter the same AST:

ProfileMean TimeNotes
none20.70 msNo filtering
full22.10 msAll features enabled
article21.80 msBlog/article content
comment23.27 msUser comments
minimal22.90 msBasic text formatting

Safe Mode

Safe mode has negligible performance impact:

ModeMean Time
Disabled20.01 ms
Enabled20.54 ms

Memory Usage

Memory scales approximately linearly with document size:

Input SizePeak MemoryRatio
11 KB72 MB~6500x
57 KB72 MB~1260x
226 KB72 MB~320x
1 MB~80 MB~80x

Note: PHP has a base memory overhead. The incremental memory per input byte is approximately 30-45x.

Running Benchmarks

bash
# Internal PHP benchmark
php tests/benchmark/benchmark.php

# PHP alternatives comparison
cd tests/benchmark_alternatives
composer install
php benchmark.php

# Cross-language comparison
./tests/benchmark/run-all.sh --compare

Key Takeaways

  1. Throughput: PHP djot-php processes ~2.0-2.4 MB/s of djot content (with OPcache)
  2. vs CommonMark (Full): djot-php is 2x faster with equivalent features
  3. vs Parsedown: Parsedown is 6-7x faster but lacks advanced features
  4. Scaling: Performance scales linearly with document size (O(n))
  5. vs Rust/Go: Native implementations are 6-12x faster (as expected)
  6. vs JavaScript: Reference JS implementation is ~3x faster
  7. Safe mode: No significant performance penalty
  8. OPcache: Enable OPcache for best performance (~2x improvement)

Released under the MIT License.