Skip to content

Commit 15a1216

Browse files
committed
feat: add parallel processing infrastructure
Adds comprehensive parallel processing infrastructure for documentation builds using pcntl_fork with copy-on-write memory semantics. New Classes: - Build/Parallel: CpuDetector, ProcessManager, ParallelSettings - Compiler/Parallel: ParallelCompiler, DocumentCompilationResult - Renderer/Parallel: ForkingRenderer, DocumentNavigationProvider, StaticDocumentIterator - Pipeline: SingleForkPipeline Features: - Cross-platform CPU detection (Linux, macOS, BSD) - Phase-based parallel compilation (Collection → Merge → Resolution → Finalization) - Parallel Twig rendering with pre-computed navigation - Non-blocking wait with configurable timeout (default 300s) - Graceful fallback to sequential processing when pcntl unavailable - Secure temp file handling with signal-based cleanup
1 parent 5820131 commit 15a1216

21 files changed

+4076
-0
lines changed

docs/cli/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ to learn more about the configuration.
4545
:hidden:
4646

4747
configuration
48+
parallel-processing
4849

4950
Extending
5051
=========

docs/cli/parallel-processing.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.. include:: /include.rst.txt
2+
3+
===================
4+
Parallel Processing
5+
===================
6+
7+
The guides tool can render your documentation using multiple CPU cores,
8+
significantly reducing build times for large documentation projects.
9+
10+
.. note::
11+
12+
Parallel processing requires the ``pcntl`` PHP extension, which is only
13+
available on Linux and macOS. On Windows, the tool falls back to
14+
sequential processing automatically.
15+
16+
Automatic Detection
17+
===================
18+
19+
By default, the guides tool automatically:
20+
21+
1. **Detects** available CPU cores on your system
22+
2. **Enables** parallel processing when beneficial
23+
3. **Falls back** to sequential when parallel isn't available
24+
25+
No configuration is required—parallel processing works out of the box.
26+
27+
When Parallel Processing Is Used
28+
================================
29+
30+
The tool uses parallel processing when:
31+
32+
- The ``pcntl`` PHP extension is available
33+
- Your documentation has 10 or more files
34+
- Multiple CPU cores are detected
35+
36+
For small documentation sets (< 10 files), sequential processing is used
37+
as the forking overhead isn't worth it.
38+
39+
Requirements
40+
============
41+
42+
- **PHP Extension**: ``pcntl`` (included in most Linux/macOS PHP builds)
43+
- **Operating System**: Linux or macOS (Windows not supported)
44+
- **PHP Version**: 8.1 or higher
45+
46+
To check if pcntl is available:
47+
48+
.. code-block:: bash
49+
50+
php -m | grep pcntl
51+
52+
Performance Benefits
53+
====================
54+
55+
The performance gain depends on:
56+
57+
- **Number of CPU cores**: More cores = more parallel workers
58+
- **Documentation size**: Larger projects benefit more
59+
- **I/O speed**: SSD storage helps maximize throughput
60+
61+
Typical speedups:
62+
63+
- 4-core system: ~2-3x faster
64+
- 8-core system: ~4-6x faster
65+
- 16-core system: ~6-10x faster
66+
67+
Troubleshooting
68+
===============
69+
70+
If parallel processing isn't working:
71+
72+
1. **Check pcntl extension**:
73+
74+
.. code-block:: bash
75+
76+
php -m | grep pcntl
77+
78+
If not listed, install it or enable it in your php.ini.
79+
80+
2. **Check file count**: With fewer than 10 files, sequential is used.
81+
82+
3. **Check logs**: Enable verbose output to see processing mode:
83+
84+
.. code-block:: bash
85+
86+
./vendor/bin/guides docs -v
87+
88+
For Developers
89+
==============
90+
91+
For implementation details and integration into custom applications,
92+
see :doc:`/developers/parallel-processing`.

docs/developers/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ it in some other way that is not possible with the ``guides`` command line tool.
1414
extensions/index
1515
compiler
1616
directive
17+
parallel-processing

0 commit comments

Comments
 (0)