Skip to content

Solver context reuse#261

Draft
tameware wants to merge 4 commits into
dds-bridge:developfrom
tameware:ddss-fable-context-reuse
Draft

Solver context reuse#261
tameware wants to merge 4 commits into
dds-bridge:developfrom
tameware:ddss-fable-context-reuse

Conversation

@tameware

Copy link
Copy Markdown
Collaborator

Written by Fable after its inspection of @BSalita's DDSS fork. Gives a 1% to 4% multi-threaded performance improvement and a barely measurable 0.1% improvement on single-thread performance.

Per Fable:

ddss-fable-context-reuse implements half of the ddss port: batch workers now get a persistent thread_local SolverContext instead of a fresh one per chunk (calc) or per board (solve). Since the worker pool keeps its threads alive, each worker's transposition table now survives across boards, chunks, and consecutive batch calls — this is where the per-batch TT allocation churn was.

tameware and others added 2 commits July 23, 2026 09:14
Avoid create/join on every multi-worker parallel_all_boards_n call so large
chunked batches do not pay thread startup cost repeatedly.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ths.

Batch workers previously created a fresh SolverContext (and transposition
table) per chunk in calc and per board in solve. With the persistent worker
pool, a thread_local context now survives across boards, chunks and
consecutive batch calls, removing TT allocation churn.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

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.

Pull request overview

This PR improves batch-solving performance by reusing per-worker SolverContext instances (and their transposition tables) across boards and across consecutive batch calls, enabled by switching board dispatch to a persistent (grow-only) worker thread pool.

Changes:

  • Replaced spawn-per-call board dispatch with a persistent process-local worker pool for parallel_all_boards_n.
  • Introduced dds::internal::worker_solver_context() as a thread_local persistent SolverContext and wired it into batch solve/calc paths.
  • Added/extended system tests to validate correctness and reuse (thread reuse + context reuse) across consecutive batch calls.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
specs/system-concurrency.md Documents the persistent thread-pool behavior for multi-worker runs.
library/tests/system/worker_context_reuse_test.cpp New tests validating per-thread context reuse and correctness across repeated batch calls.
library/tests/system/parallel_boards_test.cpp New tests validating multi-worker dispatch correctness, fail-fast behavior, and thread reuse across calls.
library/tests/system/BUILD.bazel Registers the new worker_context_reuse_test target.
library/src/system/parallel_boards.hpp Documents persistent pool behavior and adds a test seam for thread-creation count.
library/src/system/parallel_boards.cpp Implements the persistent worker pool and exposes the thread-creation counter.
library/src/solver_context/solver_context.hpp Declares internal per-thread persistent context accessors + counter seam.
library/src/solver_context/solver_context.cpp Implements the thread_local worker context holder and creation counter.
library/src/solve_board.cpp Uses solve_board(SolverContext&, ...) with worker_solver_context() in batch solve paths.
library/src/calc_tables.cpp Uses worker_solver_context() for both sequential and parallel batch-calc paths (removing per-call context allocation).

Comment thread library/src/system/parallel_boards.cpp
Comment thread library/tests/system/parallel_boards_test.cpp Outdated
tameware and others added 2 commits July 23, 2026 12:21
The pool tracks a single outstanding job, so two threads dispatching batches at the same time could overwrite each other's job and leave one caller waiting forever. run() now holds a run-scoped mutex; concurrent callers queue instead of deadlocking.

Co-authored-by: Cursor <cursoragent@cursor.com>
EXPECT does not abort, so an out-of-range bno could crash with OOB access before the test reported a clean failure. Guard the bounds check and return an error instead of indexing.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment on lines +166 to +170
if (local.finished->fetch_add(1, std::memory_order_acq_rel) + 1 >=
local.workers)
{
cv_done_.notify_one();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants