Skip to content

Commit 63e7c41

Browse files
authored
Merge pull request #84 from MatrixAI/feature-read-buffer-fix
fix: added `readableChunkSize` parameter to config and defaulted the …
2 parents b8fae9c + 51cdc5f commit 63e7c41

File tree

4 files changed

+62
-16
lines changed

4 files changed

+62
-16
lines changed

package-lock.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QUICStream.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,11 @@ class QUICStream implements ReadableWritablePair<Uint8Array, Uint8Array> {
239239
// This will setup the readable chunk buffer with the size set to the
240240
// configured per-stream buffer size. Note that this doubles the memory
241241
// usage of each stream due to maintaining both the Rust and JS buffers
242-
if (this.type === 'uni') {
243-
if (initiated === 'local') {
244-
// We expect the readable stream to be closed
245-
this.readableChunk = undefined;
246-
} else if (initiated === 'peer') {
247-
this.readableChunk = Buffer.allocUnsafe(config.initialMaxStreamDataUni);
248-
}
249-
} else if (this.type === 'bidi' && initiated === 'local') {
250-
this.readableChunk = Buffer.allocUnsafe(
251-
config.initialMaxStreamDataBidiLocal,
252-
);
253-
} else if (this.type === 'bidi' && initiated === 'peer') {
254-
this.readableChunk = Buffer.allocUnsafe(
255-
config.initialMaxStreamDataBidiRemote,
256-
);
242+
if (this.type === 'uni' && initiated === 'local') {
243+
// We expect the readable stream to be closed
244+
this.readableChunk = undefined;
245+
} else {
246+
this.readableChunk = Buffer.allocUnsafe(config.readableChunkSize);
257247
}
258248
if (this.type === 'uni' && initiated === 'local') {
259249
// This is just a dummy stream that will be auto-closed during creation

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const clientDefault: QUICConfig = {
6161
disableActiveMigration: true,
6262
applicationProtos: ['quic'],
6363
enableEarlyData: true,
64+
readableChunkSize: 4 * 1024,
6465
};
6566

6667
const serverDefault: QUICConfig = {
@@ -83,6 +84,7 @@ const serverDefault: QUICConfig = {
8384
disableActiveMigration: true,
8485
applicationProtos: ['quic'],
8586
enableEarlyData: true,
87+
readableChunkSize: 4 * 1024,
8688
};
8789

8890
/**

src/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ type QUICConfig = {
177177
logKeys?: string;
178178

179179
/**
180-
* Enable "Generate Random extensions and Sustain Extensibilty".
180+
* Enable "Generate Random extensions and Sustain Extensibility".
181181
* This prevents protocol ossification by periodically introducing
182182
* random no-op values in the optional fields in TLS.
183183
* This defaults to true.
@@ -305,6 +305,12 @@ type QUICConfig = {
305305
applicationProtos: string[];
306306

307307
enableEarlyData: boolean;
308+
309+
/**
310+
* Defines the size of the Buffer used to read out data from the readable stream.
311+
* This affects amount of memory reserved by the stream.
312+
*/
313+
readableChunkSize: number;
308314
};
309315

310316
type QUICClientConfigInput = Partial<QUICConfig>;

0 commit comments

Comments
 (0)