Skip to content

Commit b0510ea

Browse files
author
Luca Forstner
authored
ref: Run upload preparation with maximum concurrency (#382)
1 parent fb94725 commit b0510ea

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- "You know what they say ‘Fool me once, strike one, but fool me twice… strike three.’" — Michael Scott
66

7+
## 0.6.1
8+
9+
- ref: Run upload preparation with maximum concurrency (#382)
10+
711
## 0.6.0
812

913
- feat(webpack): Add debug ID injection to the webpack plugin (#198)

packages/bundler-plugin-core/src/debug-id.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export async function prepareBundleForDebugIdUpload(
6767
bundleFilePath,
6868
bundleContent,
6969
logger
70-
).then(async (sourceMapPath): Promise<void> => {
70+
).then(async (sourceMapPath) => {
7171
if (sourceMapPath) {
72-
return await prepareSourceMapForDebugIdUpload(
72+
await prepareSourceMapForDebugIdUpload(
7373
sourceMapPath,
7474
path.join(uploadFolder, `${uniqueUploadName}.js.map`),
7575
debugId,
@@ -78,7 +78,8 @@ export async function prepareBundleForDebugIdUpload(
7878
}
7979
});
8080

81-
return Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]);
81+
await writeSourceFilePromise;
82+
await writeSourceMapFilePromise;
8283
}
8384

8485
/**

packages/bundler-plugin-core/src/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,31 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
321321
path.join(os.tmpdir(), "sentry-bundler-plugin-upload-")
322322
);
323323

324-
await Promise.all(
325-
debugIdChunkFilePaths.map(async (chunkFilePath, chunkIndex): Promise<void> => {
324+
// Preparing the bundles can be a lot of work and doing it all at once has the potential of nuking the heap so
325+
// instead we do it with a maximum of 16 concurrent workers
326+
const preparationTasks = debugIdChunkFilePaths.map(
327+
(chunkFilePath, chunkIndex) => async () => {
326328
await prepareBundleForDebugIdUpload(
327329
chunkFilePath,
328330
await sourceFileUploadFolderPromise,
329331
String(chunkIndex),
330332
logger
331333
);
332-
})
334+
}
333335
);
336+
const workers: Promise<void>[] = [];
337+
const worker = async () => {
338+
while (preparationTasks.length > 0) {
339+
const task = preparationTasks.shift();
340+
if (task) {
341+
await task();
342+
}
343+
}
344+
};
345+
for (let workerIndex = 0; workerIndex < 16; workerIndex++) {
346+
workers.push(worker());
347+
}
348+
await Promise.all(workers);
334349

335350
tmpUploadFolder = await sourceFileUploadFolderPromise;
336351
await uploadDebugIdSourcemaps(internalOptions, ctx, tmpUploadFolder, releaseName);

0 commit comments

Comments
 (0)