perf: reduce chunk size from 32MB to 8MB for better parallelism

A 46MB file now splits into 6 chunks (all 6 streams active) instead
of 2 chunks (4 streams idle). Better saturation of available bandwidth
on high-latency or constrained links.
This commit is contained in:
Zac Gaetano 2026-04-09 22:07:09 -04:00
parent f7d8ba14cf
commit 009530416f

View file

@ -1128,14 +1128,14 @@ async function startUpload() {
// ============================================================
// HTTP MULTI-PART UPLOAD
// Small files (<= 32 MB): single presigned PUT direct to S3.
// Large files (> 32 MB): S3 multipart with presigned part URLs —
// browser PUTs each 32 MB chunk directly to S3, 6 in parallel.
// Small files (<= 8 MB): single presigned PUT direct to S3.
// Large files (> 8 MB): S3 multipart with presigned part URLs —
// browser PUTs each 8 MB chunk directly to S3, 6 in parallel.
// Node only signs URLs; file data never touches the server.
// Falls back to server-proxied chunked upload if presigned fails.
// ============================================================
const UPLOAD_CONCURRENCY = 6; // concurrent file uploads
const CHUNK_SIZE = 32 * 1024 * 1024; // 32 MB per chunk
const CHUNK_SIZE = 8 * 1024 * 1024; // 8 MB per chunk
const CHUNKS_PARALLEL = 6; // concurrent chunks per file
// Helper: PUT a blob to a presigned URL, return ETag from response
@ -1161,7 +1161,7 @@ async function uploadFilePresigned(item, idx) {
const mime = item.file.type || 'application/octet-stream';
const totalParts = Math.max(1, Math.ceil(item.file.size / CHUNK_SIZE));
// Small files (<= 32 MB): single presigned PUT
// Small files (<= 8 MB): single presigned PUT
if (totalParts === 1) {
setFileStatus(idx, 'uploading', 'Getting URL\u2026');
const pre = await api('POST', '/api/presigned', {
@ -1193,7 +1193,7 @@ async function uploadFilePresigned(item, idx) {
});
}
// Large files (> 32 MB): presigned multipart \u2014 browser \u2192 S3 direct
// Large files (> 8 MB): presigned multipart \u2014 browser \u2192 S3 direct
setFileStatus(idx, 'uploading', 'Initiating\u2026');
const init = await api('POST', '/api/desktop/multipart/init', {
filename: item.name, prefix: selectedPrefix, size: item.file.size, totalParts,