Skip to content

Parallelize automatic section-search with workers#30

Open
0hmX wants to merge 1 commit intomainfrom
codex/implement-parallel-section-solver
Open

Parallelize automatic section-search with workers#30
0hmX wants to merge 1 commit intomainfrom
codex/implement-parallel-section-solver

Conversation

@0hmX
Copy link
Copy Markdown
Contributor

@0hmX 0hmX commented Apr 9, 2026

Motivation

  • Reduce wall-clock time of the automatic section-mask search by parallelizing candidate evaluation across worker threads.
  • Avoid expensive search overhead on easy circuits by skipping the automatic search when the baseline max-region cost is already low.
  • Improve final section selection by merging non-overlapping improving candidates and choosing the best merged mask.

Description

  • Adds worker-based parallel search by introducing parallelSectionSearchWorker.ts and spawning Worker threads from TinyHyperGraphSectionPipelineSolver, with shared memory helpers (shareInt32Array, shareFloat64Array, shareInt8Array).
  • Implements candidate chunking, worker lifecycle (startCandidateChunkWorker, finishCandidateChunkWorker), and result aggregation including ImprovementEntry and non-overlapping selection via selectNonOverlappingImprovements and getMergedMask.
  • Adds a low-baseline-cost guard (minBaselineMaxRegionCostToSearch config + DEFAULT_MIN_BASELINE_MAX_REGION_COST_TO_SEARCH) that causes the search to be skipped and records sectionSearchSkipped in solver state and stats.
  • Changes problem/port mask handling to use shared buffers for worker use and avoids unnecessary array copying in createProblemWithPortSectionMask for the main thread.
  • Ensures pipeline output selection prefers the better of solveGraph and optimizeSection outputs and falls back to the baseline when search was skipped.
  • Records additional timing and bookkeeping stats for generated/eligible/duplicate candidates and whether the search was skipped.

Testing

  • Updated tests/solver/section-solver.test.ts and added section pipeline skips automatic search on low-baseline-cost circuits to assert skipping behavior and stats; the test suite covering section-pipeline behavior was executed locally and passed.
  • Existing section-pipeline tests (including multi-mask search and MAX_HOT_REGIONS handling) were run and passed.

Codex Task

@0hmX 0hmX force-pushed the codex/implement-parallel-section-solver branch from 391f4ce to 9dfbb30 Compare April 9, 2026 16:12
@0hmX 0hmX marked this pull request as ready for review April 10, 2026 16:38
import { BasePipelineSolver } from "@tscircuit/solver-utils"
import type { GraphicsObject } from "graphics-debug"
import { cpus, tmpdir } from "node:os"
import { mkdtempSync, readFileSync, rmSync } from "node:fs"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't run in a browser

@0hmX 0hmX changed the title Parallelize automatic section-search with workers, add low-cost skip and merge improvements Parallelize automatic section-search with workers Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants