perf: 16x larger chunks + native backpressure for faster transfers
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 41s
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 41s
- CHUNK_SIZE: 16 KB → 256 KB (16x fewer send calls) - MAX_BUFFER: 1 MB → 4 MB (more data in flight) - waitForDrain: polling setTimeout → native bufferedamountlow event Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8212bc7391
commit
62aeb895c1
@ -164,8 +164,8 @@ export interface PushPayload {
|
|||||||
|
|
||||||
// ── Constants ──
|
// ── Constants ──
|
||||||
|
|
||||||
export const CHUNK_SIZE = 16 * 1024; // 16 KB
|
export const CHUNK_SIZE = 256 * 1024; // 256 KB
|
||||||
export const MAX_BUFFER = 1024 * 1024; // 1 MB backpressure threshold
|
export const MAX_BUFFER = 4 * 1024 * 1024; // 4 MB backpressure threshold
|
||||||
|
|
||||||
export const SHORT_CODE_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
|
export const SHORT_CODE_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
|
||||||
export const SHORT_CODE_LENGTH = 3;
|
export const SHORT_CODE_LENGTH = 3;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -89,15 +89,16 @@ export async function sendFile(
|
|||||||
|
|
||||||
function waitForDrain(peer: SimplePeer.Instance): Promise<void> {
|
function waitForDrain(peer: SimplePeer.Instance): Promise<void> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const check = () => {
|
const channel = (peer as any)._channel as RTCDataChannel | undefined;
|
||||||
const channel = (peer as any)._channel as RTCDataChannel | undefined;
|
if (!channel || channel.bufferedAmount < MAX_BUFFER) {
|
||||||
if (!channel || channel.bufferedAmount < MAX_BUFFER) {
|
resolve();
|
||||||
resolve();
|
return;
|
||||||
} else {
|
}
|
||||||
setTimeout(check, 10);
|
channel.bufferedAmountLowThreshold = MAX_BUFFER / 2;
|
||||||
}
|
channel.onbufferedamountlow = () => {
|
||||||
|
channel.onbufferedamountlow = null;
|
||||||
|
resolve();
|
||||||
};
|
};
|
||||||
check();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user