Closed
Bug 977009
Opened 11 years ago
Closed 11 years ago
Use Cu.cloneInto() instead of JSON.parse(JSON.stringify(obj))
Categories
(DevTools :: General, defect)
DevTools
General
Tracking
(Not tracked)
VERIFIED
FIXED
Firefox 32
People
(Reporter: ttaubert, Assigned: Gijs)
Details
(Whiteboard: p=1 s=it-32c-31a-30b.3 [qa-])
Attachments
(1 file)
5.84 KB,
patch
|
vporof
:
review+
|
Details | Diff | Splinter Review |
JSON.parse(JSON.stringify()) is slow. We should rather use Cu.cloneInto() when we want to clone an object. I found several occurrences in devtools code:
browser/devtools/framework/connect/connect.js:87: let globals = JSON.parse(JSON.stringify(aResponse));
browser/devtools/profiler/cleopatra/js/parserWorker.js:704: gProfiles[profileID] = JSON.parse(JSON.stringify({
browser/devtools/shared/Parser.jsm:428: let loc = JSON.parse(JSON.stringify(parentLocation));
browser/devtools/shared/Parser.jsm:436: let loc = JSON.parse(JSON.stringify(parentLocation));
browser/devtools/shared/Parser.jsm:444: let loc = JSON.parse(JSON.stringify(parentLocation));
browser/devtools/shared/Parser.jsm:452: let loc = JSON.parse(JSON.stringify(parentLocation));
browser/devtools/shared/Parser.jsm:462: let loc = JSON.parse(JSON.stringify(nodeLocation));
browser/devtools/webconsole/hudservice.js:194: let globals = JSON.parse(JSON.stringify(aResponse));
If you want to clone |obj| into a new object you can do:
let newObj = Cu.cloneInto(obj, {});
Reporter | ||
Comment 1•11 years ago
|
||
But wait, there is more:
toolkit/devtools/server/actors/profiler.js:174: let subj = JSON.parse(JSON.stringify(aSubject, cycleBreaker));
toolkit/devtools/server/actors/profiler.js:175: let data = JSON.parse(JSON.stringify(aData, cycleBreaker));
toolkit/devtools/server/actors/root.js:354: return JSON.parse(JSON.stringify(aRequest));
toolkit/devtools/server/protocol.js:608: return JSON.parse(JSON.stringify(this.template, function(key, value) {
Comment 2•11 years ago
|
||
Nice! <3
Assignee | ||
Comment 3•11 years ago
|
||
I haven't touched all of these cases, because there's some that use a second argument to JSON.stringify to filter output, and cloneInto can't do that. Try push: https://tbpl.mozilla.org/?tree=Try&rev=9fa3dea02817
Attachment #8428663 -
Flags: review?(vporof)
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → gijskruitbosch+bugs
Status: NEW → ASSIGNED
Comment 4•11 years ago
|
||
Comment on attachment 8428663 [details] [diff] [review]
switch to Cu.cloneInto instead of JSON.parse(JSON.stringify(foo)) because it's faster,
Review of attachment 8428663 [details] [diff] [review]:
-----------------------------------------------------------------
Assuming all tests still pass.
Attachment #8428663 -
Flags: review?(vporof) → review+
Assignee | ||
Comment 5•11 years ago
|
||
Green apart from an intermittent, which I've filed as bug 1016024
remote: https://hg.mozilla.org/integration/fx-team/rev/de783743ebcd
Whiteboard: [fixed-in-fx-team]
Assignee | ||
Comment 6•11 years ago
|
||
Sigh. Except xpcshell tests (which I didn't think to include in my trypushes) went orange, because Cu is not defined in the server root actor:
remote: https://hg.mozilla.org/integration/fx-team/rev/fa3cb3c36c30
Comment 7•11 years ago
|
||
Pretty sure this is going to break Eddy's work of making the server run without chrome code so that it can be in a worker.
Flags: needinfo?(ejpbruel)
Comment 8•11 years ago
|
||
(In reply to Nick Fitzgerald [:fitzgen] from comment #7)
> Pretty sure this is going to break Eddy's work of making the server run
> without chrome code so that it can be in a worker.
Yes, this will break the worker debugger, where Cu is not available. We might be able to come up with a replacement API for Cu.cloneInto in a worker, but we should hold off on this until worker debugging lands.
Assignee | ||
Comment 9•11 years ago
|
||
(In reply to Eddy Bruel [:ejpbruel] from comment #8)
> (In reply to Nick Fitzgerald [:fitzgen] from comment #7)
> > Pretty sure this is going to break Eddy's work of making the server run
> > without chrome code so that it can be in a worker.
>
> Yes, this will break the worker debugger, where Cu is not available. We
> might be able to come up with a replacement API for Cu.cloneInto in a
> worker, but we should hold off on this until worker debugging lands.
I'm not clear on what you mean here. Do you mean this patch needs to be backed out?
Comment 10•11 years ago
|
||
(In reply to :Gijs Kruitbosch from comment #9)
> (In reply to Eddy Bruel [:ejpbruel] from comment #8)
> > (In reply to Nick Fitzgerald [:fitzgen] from comment #7)
> > > Pretty sure this is going to break Eddy's work of making the server run
> > > without chrome code so that it can be in a worker.
> >
> > Yes, this will break the worker debugger, where Cu is not available. We
> > might be able to come up with a replacement API for Cu.cloneInto in a
> > worker, but we should hold off on this until worker debugging lands.
>
> I'm not clear on what you mean here. Do you mean this patch needs to be
> backed out?
Actually, we should be able to do is something like:
if (Cu.cloneInto)
Cu.cloneInto(...)
else
JSON.parse(JSON.stringify)
to make it work inside a worker, in which case this is fine, and you don't have to do anything.
But please, in the future, notify me of these things *before* you land them!
Flags: needinfo?(ejpbruel)
Comment 11•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/de783743ebcd
https://hg.mozilla.org/mozilla-central/rev/fa3cb3c36c30
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 32
Assignee | ||
Comment 12•11 years ago
|
||
Marco, can you add this to this iteration?
Status: RESOLVED → VERIFIED
Whiteboard: p=1 [qa-]
Assignee | ||
Comment 13•11 years ago
|
||
(In reply to :Gijs Kruitbosch from comment #12)
> Marco, can you add this to this iteration?
Flags: needinfo?(mmucci)
Comment 14•11 years ago
|
||
Added to Iteration 32.3
Flags: needinfo?(mmucci)
Whiteboard: p=1 [qa-] → p=1 s=it-32c-31a-30b.3 [qa-]
Updated•7 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•