Bug 1449162 - Type everything to json and manually manage and marshall. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 09 May 2018 07:20:51 -0700
changeset 800606 9d4768658d802ac01166b7a0f5d217f553bcb41c
parent 800605 cb48b9869f94a634de30085537c1baf6bfe7d576
child 802297 ac1ffadfeada0f952bb97875dd3fc4b243c169e4
child 803475 7f05812e5bf762d3a8ceb7e82ca87db41411700b
push id111423
push userbmo:poirot.alex@gmail.com
push dateMon, 28 May 2018 16:48:32 +0000
reviewersjryans
bugs1449162
milestone62.0a1
Bug 1449162 - Type everything to json and manually manage and marshall. r=jryans MozReview-Commit-ID: JOM60IW9g6e
devtools/server/actors/network-event.js
devtools/server/actors/stylesheets.js
devtools/shared/specs/network-event.js
--- a/devtools/server/actors/network-event.js
+++ b/devtools/server/actors/network-event.js
@@ -270,16 +270,20 @@ const NetworkEventActor = protocol.Actor
    *        The raw headers source.
    */
   addRequestHeaders(headers, rawHeaders) {
     this._request.headers = headers;
     this._prepareHeaders(headers);
 
     if (rawHeaders) {
       rawHeaders = new LongStringActor(this.conn, rawHeaders);
+      // bug 1462561 - Use "json" type and manually manage/marshall actors to woraround
+      // protocol.js performance issue
+      this.manage(rawHeaders);
+      rawHeaders = rawHeaders.form();
     }
     this._request.rawHeaders = rawHeaders;
 
     this.emit("network-event-update:headers", "requestHeaders", {
       headers: headers.length,
       headersSize: this._request.headersSize,
     });
   },
@@ -303,34 +307,42 @@ const NetworkEventActor = protocol.Actor
    * Add network request POST data.
    *
    * @param object postData
    *        The request POST data.
    */
   addRequestPostData(postData) {
     this._request.postData = postData;
     postData.text = new LongStringActor(this.conn, postData.text);
+    // bug 1462561 - Use "json" type and manually manage/marshall actors to woraround
+    // protocol.js performance issue
+    this.manage(postData.text);
+    let dataSize = postData.text.str.length;
+    postData.text = postData.text.form();
 
     this.emit("network-event-update:post-data", "requestPostData", {
-      dataSize: postData.text.str.length,
+      dataSize,
       discardRequestBody: this._discardRequestBody,
     });
   },
 
   /**
    * Add the initial network response information.
    *
    * @param object info
    *        The response information.
    * @param string rawHeaders
    *        The raw headers source.
    */
   addResponseStart(info, rawHeaders) {
     rawHeaders = new LongStringActor(this.conn, rawHeaders);
-    this._response.rawHeaders = rawHeaders;
+    // bug 1462561 - Use "json" type and manually manage/marshall actors to woraround
+    // protocol.js performance issue
+    this.manage(rawHeaders);
+    this._response.rawHeaders = rawHeaders.form();
 
     this._response.httpVersion = info.httpVersion;
     this._response.status = info.status;
     this._response.statusText = info.statusText;
     this._response.headersSize = info.headersSize;
     // Consider as not discarded if info.discardResponseBody is undefined
     this._discardResponseBody = !!info.discardResponseBody;
 
@@ -394,16 +406,20 @@ const NetworkEventActor = protocol.Actor
    *          Tells if the response content was recorded or not.
    *        - boolean truncated
    *          Tells if the some of the response content is missing.
    */
   addResponseContent(content, {discardResponseBody, truncated}) {
     this._truncated = truncated;
     this._response.content = content;
     content.text = new LongStringActor(this.conn, content.text);
+    // bug 1462561 - Use "json" type and manually manage/marshall actors to woraround
+    // protocol.js performance issue
+    this.manage(content.text);
+    content.text = content.text.form();
 
     this.emit("network-event-update:response-content", "responseContent", {
       mimeType: content.mimeType,
       contentSize: content.size,
       encoding: content.encoding,
       transferredSize: content.transferredSize,
       discardResponseBody,
     });
@@ -437,13 +453,17 @@ const NetworkEventActor = protocol.Actor
    * LongStringActor for the header values, when needed.
    *
    * @private
    * @param array aHeaders
    */
   _prepareHeaders(headers) {
     for (let header of headers) {
       header.value = new LongStringActor(this.conn, header.value);
+      // bug 1462561 - Use "json" type and manually manage/marshall actors to woraround
+      // protocol.js performance issue
+      this.manage(header.value);
+      header.value = header.value.form();
     }
   },
 });
 
 exports.NetworkEventActor = NetworkEventActor;
--- a/devtools/server/actors/stylesheets.js
+++ b/devtools/server/actors/stylesheets.js
@@ -156,20 +156,31 @@ function fetchStylesheetFromNetworkMonit
   let request = consoleActor.getNetworkEventActorForURL(href);
   if (!request) {
     return null;
   }
   let content = request._response.content;
   if (request._discardResponseBody || request._truncated || !content) {
     return null;
   }
-  // `content.text` is a LongStringActor instance
-  // Get a reference to the raw string via `str` property
+
+  if (content.text.type != "longString") {
+    // For short strings, the text is available directly.
+    return {
+      content: content.text,
+      contentType: content.mimeType,
+    };
+  }
+  // For long strings, look up the actor that holds the full text.
+  let longStringActor = consoleActor.conn._getOrCreateActor(content.text.actor);
+  if (!longStringActor) {
+    return null;
+  }
   return {
-    content: content.text.str,
+    content: longStringActor.str,
     contentType: content.mimeType,
   };
 }
 
 /**
  * Get the charset of the stylesheet.
  */
 function getCSSCharset(sheet) {
--- a/devtools/shared/specs/network-event.js
+++ b/devtools/shared/specs/network-event.js
@@ -158,49 +158,49 @@ const networkEventSpec = generateActorSp
 
   methods: {
     release: {
       // This makes protocol.js call destroy method
       release: true
     },
     getRequestHeaders: {
       request: {},
-      response: RetVal("netevent.headers")
+      response: RetVal("json")
     },
     getRequestCookies: {
       request: {},
-      response: RetVal("netevent.cookies")
+      response: RetVal("json")
     },
     getRequestPostData: {
       request: {},
-      response: RetVal("netevent.postdata")
+      response: RetVal("json")
     },
     getResponseHeaders: {
       request: {},
-      response: RetVal("netevent.headers")
+      response: RetVal("json")
     },
     getResponseCookies: {
       request: {},
-      response: RetVal("netevent.cookies")
+      response: RetVal("json")
     },
     getResponseCache: {
       request: {},
-      response: RetVal("netevent.cache")
+      response: RetVal("json")
     },
     getResponseContent: {
       request: {},
-      response: RetVal("netevent.content")
+      response: RetVal("json")
     },
     getEventTimings: {
       request: {},
-      response: RetVal("netevent.timings")
+      response: RetVal("json")
     },
     getSecurityInfo: {
       request: {},
-      response: RetVal("netevent.secinfo")
+      response: RetVal("json")
     },
     getStackTrace: {
       request: {},
       // stacktrace is an "array:string", but not always.
       response: RetVal("json")
     },
   }
 });