Phase C: back parallel fan-outs with Void ThreadPool

Replace the per-call std::async OS-thread spawns in the blocking
fan-out/collect paths with a bounded Void::Concurrency::ThreadPool member,
giving thread reuse instead of an unbounded thread per request:

- YouTubeClient: getVideoInfoAsync, getPlaylistAsync, and the two playlist
  resolution batches now submit to pool_. The std::future<T>/.get() join
  semantics are unchanged, so control flow is identical.
- NetworkClient: getAsync/postAsync/requestAsync (and thus requestBatch)
  submit to pool_.

populateShortenedUrls is deliberately left on std::async — it relies on
wide parallelism under a tight 5s budget, which a bounded pool would
throttle. Build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-23 03:06:44 +03:00
1 parent 51f1651c18
commit 5775c522eb
4 files changed
+27 -21

No files matched your search

+11 -10
View File
@@ -324,10 +324,9 @@ namespace Echoion::Core
std::future<Api::Result<Api::TrackInfo>>
YouTubeClient::getVideoInfoAsync(std::string_view videoId)
{
return std::async(std::launch::async,
[this, videoIdStr = std::string(videoId)]() {
return getVideoInfo(videoIdStr);
});
return pool_.submit([this, videoIdStr = std::string(videoId)]() {
return getVideoInfo(videoIdStr);
});
}
std::vector<Api::Result<Api::TrackInfo>> YouTubeClient::getVideoInfoBatch(
@@ -840,7 +839,7 @@ namespace Echoion::Core
// Launch concurrent resolutions for this batch
for (size_t j = i; j < end; ++j) {
futures.push_back(
std::async(std::launch::async, [this, &items, j]() {
pool_.submit([this, &items, j]() {
return resolveTrackWithYtDlp(items[j]);
}));
}
@@ -884,10 +883,9 @@ namespace Echoion::Core
std::future<Api::Result<Api::PlaylistInfo>>
YouTubeClient::getPlaylistAsync(std::string_view playlistId)
{
return std::async(std::launch::async,
[this, playlistIdStr = std::string(playlistId)]() {
return getPlaylist(playlistIdStr);
});
return pool_.submit([this, playlistIdStr = std::string(playlistId)]() {
return getPlaylist(playlistIdStr);
});
}
void YouTubeClient::getPlaylistStreaming(
@@ -942,7 +940,7 @@ namespace Echoion::Core
// Launch concurrent resolutions for this batch
for (size_t j = i; j < end; ++j) {
futures.push_back(
std::async(std::launch::async, [this, &items, j]() {
pool_.submit([this, &items, j]() {
return resolveTrackWithYtDlp(items[j]);
}));
}
@@ -1413,6 +1411,9 @@ namespace Echoion::Core
continue;
}
// Best-effort wide-parallel shortening under a tight timeout — kept
// on std::async so each track gets its own thread rather than
// queueing behind the bounded resolution pool.
futures.push_back(std::async(std::launch::async, [this, &track]() {
// Each URL shortening has its own 3-second timeout
// Use shared_ptr for safe detached thread execution