Skip to content

perf(builder): bound parallel loads by submission instead of waiting workers - #1715

Merged
rubenporras merged 1 commit into
dsldevkit:masterfrom
rubenporras:perf/parallel-loader-submit-window
Dec 4, 2026
Merged

rubenporras merged 1 commit into
dsldevkit:masterfrom
rubenporras:perf/parallel-loader-submit-window

Conversation

@rubenporras

Copy link
Copy Markdown
Member

The in-order hand-off of ParallelResourceLoader used one monitor for the results, the window and cancellation: every put() and take() called notifyAll(), waking all workers waiting in awaitTurn() although at most one of them could start. The woken workers re-acquired the monitor while the builder thread tried to enter take(), which cost the build thread about 6 s per build in phase 2.

startThreads() now submits only the loads within the window of 2 * nThreads + queueSize positions, and each result taken submits the next one, outside of any lock the workers take; the executor is shut down once the last load is submitted. The workers no longer wait for their turn, and a result put signals only the thread taking the results. Each load job is claimed either by the worker running it or by cancel(), so cancel() still returns exactly the resources whose load did not start, and no load starts after it returns.

…workers

The in-order hand-off of ParallelResourceLoader used one monitor for the
results, the window and cancellation: every put() and take() called
notifyAll(), waking all workers waiting in awaitTurn() although at most
one of them could start. The woken workers re-acquired the monitor while
the builder thread tried to enter take(), which cost the build thread
about 6 s per build in phase 2.

startThreads() now submits only the loads within the window of
2 * nThreads + queueSize positions, and each result taken submits the
next one, outside of any lock the workers take; the executor is shut
down once the last load is submitted. The workers no longer wait for
their turn, and a result put signals only the thread taking the results.
Each load job is claimed either by the worker running it or by cancel(),
so cancel() still returns exactly the resources whose load did not
start, and no load starts after it returns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@joaodinissf joaodinissf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve: the new submission-bounded hand-off is correct as far as I traced it, and I found no P1 or P2 issues.

  1. ParallelResourceLoader.java:456 (P3, pre-existing, not introduced here): parallelLoadingSupported(uri) runs outside the try in load(). If the resource service provider or injector lookup throws, the exception escapes ResourceLoadJob.run(): the job is already claimed, so no result is put, the URI stays in currentlyProcessedUris, and next() waits the full timeout (300 s by default) and abandons the whole operation. The old awaitTurn version behaves the same. Moving the call inside the try would turn this into an ordinary LoadOperationException for that URI. Optional follow-up.
  2. ParallelResourceLoaderTest.java (P3, test gap): no test for an empty workload (ParallelResourceLoader.java:363-365: shutdown, then submitLoads returns at from == to), nor for the RejectedExecutionException path at :401-403 (cancel() racing a submitLoads that already reserved its range). I traced both by hand and they are correct: the reserved jobs are claimed by cancel() and reported, and a job that still reaches a worker fails claim() and does nothing. Not required; the empty case would be cheap to add.

Checked and found correct:

  • Order and exactly-once delivery: each job is claimed exactly once through the CAS in claim(); the result is put under lock and the taker is signalled under the same lock; take() re-checks in a while (results.isEmpty()) loop, so no wake-up is lost.
  • No deadlock: workers never block, and positions submitted equal window + results handed out, so while toProcess > 0 there is always a submitted job whose result has not been taken. Holds for nThreads=1, queueSize=0 (window 2) and queueSize=-1 (all submitted, then shutdown). A failed load still advances the window, because submitLoads(1) runs before the throwable is rethrown.
  • cancel() returns exactly the loads that did not start: worker and cancel() race on claim(), the flag set under submissionLock stops later submissions, and a second cancel() returns an empty list.
  • Thread safety: submitted and jobs are only touched under submissionLock; workers see jobs[i] and inOrderResults through the happens-before edge of execute().
  • Version: the bundle is at 17.3.4 in v19.4.0 and on master; the bump to 17.3.5 is the right (micro) level.
  • CI on the head is green (checkstyle, line-endings, maven-verify, pmd).

Assisted-by: Claude:claude-opus-5-5

@joaodinissf joaodinissf added the review:approved Current head approved by review; CI and human merge gates still apply. label Dec 4, 2026
@rubenporras
rubenporras added this pull request to the merge queue Dec 4, 2026
Merged via the queue into dsldevkit:master with commit 610a3f0 Dec 4, 2026
4 checks passed
@rubenporras
rubenporras deleted the perf/parallel-loader-submit-window branch December 4, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Current head approved by review; CI and human merge gates still apply.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants