perf: de-parallelize upscale ancestor lookup to avoid thread-pool starvation - #264
Open
shimoncohen wants to merge 1 commit into
Open
perf: de-parallelize upscale ancestor lookup to avoid thread-pool starvation#264shimoncohen wants to merge 1 commit into
shimoncohen wants to merge 1 commit into
Conversation
…rvation InternalGetLastExistingTile fetched all ancestor coords via an unbounded Parallel.ForEachAsync and blocked on .Result. When called from inside the service-level Parallel.ForEach merge loop this nests parallelism and, via the sync-over-async .Result, blocks an outer worker thread while inner Task.Run items compete for the same thread pool -> starvation under load. The inner GetTile calls also serialize on the source connection, so the concurrency bought little. Replace with a sequential highest-zoom-first loop that short-circuits on the first existing tile. Same result (closest ancestor), fewer GetTile calls, no nesting, no sync-over-async. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
InternalGetLastExistingTile(Data.cs) fetched all ancestor coords for upscale via an unboundedParallel.ForEachAsyncand then blocked on.Result. When invoked from inside the service-levelParallel.ForEachmerge loop (see PR #260), this nests parallelism, and the sync-over-async.Resultblocks an outer worker thread while innerTask.Runitems compete for the same thread pool → thread-pool starvation under load. The innerGetTilecalls also serialize on the source connection, so the concurrency bought little.This addresses @asafmas-rnd's "check that Parallel doesn't call other parallel's" comment on #260 — the inner parallel is pre-existing (from #119, 2023); #260's outer parallel is what turns it into a nest.
Fix
Sequential, highest-zoom-first loop that short-circuits on the first existing tile.
coordsListis already ordered high→low zoom, so the first hit is the closest ancestor — identical result, fewerGetTilecalls, no nesting, no sync-over-async.Verification
System.Collections.Concurrent🤖 Generated with Claude Code