Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: third_party/WebKit/Source/core/streams/ReadableStream.js

Issue 2637863002: Fix ReadableStream scalability issue (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/streams/ReadableStream.js
diff --git a/third_party/WebKit/Source/core/streams/ReadableStream.js b/third_party/WebKit/Source/core/streams/ReadableStream.js
index 1586b0e61500db517bc361c1b456f8867c0db6a7..f185f6c9e57be32b05798704defbbcde174c42f5 100644
--- a/third_party/WebKit/Source/core/streams/ReadableStream.js
+++ b/third_party/WebKit/Source/core/streams/ReadableStream.js
@@ -195,7 +195,7 @@
this[_underlyingSource] = underlyingSource;
- this[_queue] = new v8.InternalPackedArray();
+ this[_queue] = new Queue();
this[_totalQueuedSize] = 0;
this[_readableStreamDefaultControllerBits] = 0b0;
@@ -296,7 +296,7 @@
}
function ReadableStreamDefaultControllerCancel(controller, reason) {
- controller[_queue] = new v8.InternalPackedArray();
+ controller[_queue] = new Queue();
const underlyingSource = controller[_underlyingSource];
return PromiseCallOrNoop(underlyingSource, 'cancel', reason, 'underlyingSource.cancel');
@@ -483,7 +483,7 @@
}
function ReadableStreamDefaultControllerError(controller, e) {
- controller[_queue] = new v8.InternalPackedArray();
+ controller[_queue] = new Queue();
const stream = controller[_controlledReadableStream];
ReadableStreamError(stream, e);
}
@@ -796,6 +796,46 @@
// can modify the queue size alongside.
//
+ // Simple queue structure. Avoids scalability issues with using
+ // InternalPackedArray directly by using multiple arrays
+ // in a linked list and keeping the size of each below 32768 elements.
+ class Queue {
+ constructor() {
+ this.front = {
+ elements: new v8.InternalPackedArray(),
+ next: undefined,
+ };
+ this.back = this.front;
+ this.size = 0;
+ }
+
+ get length() {
yhirano 2017/01/17 08:23:37 How about having |empty| predicate?
Adam Rice 2017/01/17 08:33:39 I am hoping to get feedback from someone more know
+ return this.size;
+ }
+
+ push(element) {
+ ++this.size;
+ if (this.back.elements.length === 32767) {
+ const oldBack = this.back;
+ this.back = {
+ elements: new v8.InternalPackedArray(),
+ next: undefined,
+ };
+ oldBack.next = this.back;
+ }
+ this.back.elements.push(element);
+ }
+
+ shift() {
+ --this.size;
+ const element = this.front.elements.shift();
+ if (this.front.elements.length === 0 && this.front.next !== undefined) {
+ this.front = this.front.next;
+ }
+ return element;
+ }
+ }
+
function DequeueValue(controller) {
const result = controller[_queue].shift();
controller[_totalQueuedSize] -= result.size;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698