Repository navigation
perf(builder): bound parallel loads by submission instead of waiting workers - #1715
Merged
rubenporras merged 1 commit intoDec 4, 2026
Conversation
…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
approved these changes
Dec 4, 2026
joaodinissf
left a comment
Collaborator
There was a problem hiding this comment.
Approve: the new submission-bounded hand-off is correct as far as I traced it, and I found no P1 or P2 issues.
ParallelResourceLoader.java:456(P3, pre-existing, not introduced here):parallelLoadingSupported(uri)runs outside thetryinload(). If the resource service provider or injector lookup throws, the exception escapesResourceLoadJob.run(): the job is already claimed, so no result is put, the URI stays incurrentlyProcessedUris, andnext()waits the full timeout (300 s by default) and abandons the whole operation. The oldawaitTurnversion behaves the same. Moving the call inside thetrywould turn this into an ordinaryLoadOperationExceptionfor that URI. Optional follow-up.ParallelResourceLoaderTest.java(P3, test gap): no test for an empty workload (ParallelResourceLoader.java:363-365: shutdown, thensubmitLoadsreturns atfrom == to), nor for theRejectedExecutionExceptionpath at:401-403(cancel()racing asubmitLoadsthat already reserved its range). I traced both by hand and they are correct: the reserved jobs are claimed bycancel()and reported, and a job that still reaches a worker failsclaim()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 underlockand the taker is signalled under the same lock;take()re-checks in awhile (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 > 0there 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, becausesubmitLoads(1)runs before the throwable is rethrown. cancel()returns exactly the loads that did not start: worker andcancel()race onclaim(), the flag set undersubmissionLockstops later submissions, and a secondcancel()returns an empty list.- Thread safety:
submittedandjobsare only touched undersubmissionLock; workers seejobs[i]andinOrderResultsthrough the happens-before edge ofexecute(). - 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.