Worker count for the extraction pool when the caller passed none. GRAPHIFY_MAX_WORKERS (``--max-workers`` sets it too) wins, bounded by the number of files, exactly as before. Otherwise start one worker per ``_BYTES_PER_WORKER`` of uncached source, capped at the CPU count. A big job
(uncached_work: list[tuple[int, Path]])
| 12721 | |
| 12722 | |
| 12723 | def _default_max_workers(uncached_work: list[tuple[int, Path]]) -> int: |
| 12724 | """Worker count for the extraction pool when the caller passed none. |
| 12725 | |
| 12726 | GRAPHIFY_MAX_WORKERS (``--max-workers`` sets it too) wins, bounded by the |
| 12727 | number of files, exactly as before. Otherwise start one worker per |
| 12728 | ``_BYTES_PER_WORKER`` of uncached source, capped at the CPU count. A big |
| 12729 | job still gets every core (the old cap of 8 cost a 32-thread box 4x, |
| 12730 | #792); a small one no longer starts a process per core that each load |
| 12731 | graphify and the grammars for under a second of work. |
| 12732 | """ |
| 12733 | env_raw = os.environ.get("GRAPHIFY_MAX_WORKERS", "").strip() |
| 12734 | if env_raw: |
| 12735 | try: |
| 12736 | v = int(env_raw) |
| 12737 | except ValueError: |
| 12738 | v = 0 |
| 12739 | if v > 0: |
| 12740 | return min(v, len(uncached_work)) |
| 12741 | total_bytes = 0 |
| 12742 | for _, path in uncached_work: |
| 12743 | try: |
| 12744 | total_bytes += os.path.getsize(path) |
| 12745 | except OSError: |
| 12746 | pass |
| 12747 | by_size = -(-total_bytes // _BYTES_PER_WORKER) # ceil |
| 12748 | return max(1, min(os.cpu_count() or 4, len(uncached_work), by_size)) |
| 12749 | |
| 12750 | |
| 12751 | def _extract_parallel( |