Bug 1366693 - add throttling when retrieving mutations in inspector front;r=pbro
MozReview-Commit-ID: KaXW7UeNQny
--- a/devtools/shared/fronts/inspector.js
+++ b/devtools/shared/fronts/inspector.js
@@ -15,16 +15,22 @@ const {
walkerSpec
} = require("devtools/shared/specs/inspector");
const defer = require("devtools/shared/defer");
const { Task } = require("devtools/shared/task");
loader.lazyRequireGetter(this, "nodeConstants",
"devtools/shared/dom-node-constants");
loader.lazyRequireGetter(this, "CommandUtils",
"devtools/client/shared/developer-toolbar", true);
+const { throttle } = require("devtools/client/inspector/shared/utils");
+
+/**
+ * Delay between two calls to getMutations.
+ */
+const MUTATIONS_THROTTLING_DELAY = 500;
/**
* Client side of the DOM walker.
*/
const WalkerFront = FrontClassWithSpec(walkerSpec, {
// Set to true if cleanup should be requested after every mutation list.
autoCleanup: true,
@@ -38,16 +44,25 @@ const WalkerFront = FrontClassWithSpec(w
});
}, {impl: "_pick"}),
initialize: function (client, form) {
this._createRootNodePromise();
Front.prototype.initialize.call(this, client, form);
this._orphaned = new Set();
this._retainedOrphans = new Set();
+
+ /**
+ * If many mutations are fired at the same time, clients might sequentially request
+ * children/siblings for updated nodes, which can be costly. By throttling the calls
+ * to getMutations, duplicated mutations will be ignored.
+ */
+ this._throttledGetMutations = throttle(() => {
+ this.getMutations({cleanup: this.autoCleanup}).catch(() => {});
+ }, MUTATIONS_THROTTLING_DELAY);
},
destroy: function () {
Front.prototype.destroy.call(this);
},
// Update the object given a form representation off the wire.
form: function (json) {
@@ -432,17 +447,17 @@ const WalkerFront = FrontClassWithSpec(w
}),
/**
* Handle the `new-mutations` notification by fetching the
* available mutation records.
*/
onMutations: preEvent("new-mutations", function () {
// Fetch and process the mutations.
- this.getMutations({cleanup: this.autoCleanup}).catch(() => {});
+ this._throttledGetMutations();
}),
isLocal: function () {
return !!this.conn._transport._serverConnection;
},
// XXX hack during transition to remote inspector: get a proper NodeFront
// for a given local node. Only works locally.