Closed Bug 1425577 Opened 8 years ago Closed 8 years ago

Do not create a new state for every message in a MESSAGES_ADD batch

Categories

(DevTools :: Console, enhancement, P1)

enhancement

Tracking

(firefox59 wontfix, firefox60 fixed)

RESOLVED FIXED
Firefox 60
Tracking Status
firefox59 --- wontfix
firefox60 --- fixed

People

(Reporter: nchevobbe, Assigned: nchevobbe)

References

(Blocks 1 open bug)

Details

(Whiteboard: [newconsole-mvp])

Attachments

(1 file, 7 obsolete files)

At the moment, we clone the state for each addMessage call, which is call by the MESSAGES_ADD action. This is pointless since we have batching, and we should only clone the state once, and add all the message of the batch to it.
Blocks: console-perf
Priority: -- → P2
Whiteboard: [newconsole-mvp]
Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Priority: P2 → P1
Okay, so I have a patch which I'll put up for review after this comment. It adds a bit of complexity, and there was no improvement on DAMP. However, I do have a case where we can see nice benefits. So here is the test case : ```js let i = 0; function streamLogs() { console.log(i++); if (i < 500) { requestAnimationFrame(streamLogs) } } streamLogs(); ``` in short, streaming logs (i.e. adding lots of messages in a short timespan). Here's the profile without the patch : - https://perfht.ml/2B82mUg - 4% (366ms of 7756ms) of the total time is spent on the messages reducer Here's the profile with the patch: - https://perfht.ml/2B3VUNL - 1% (125ms of 6966ms) of the total time is spent on the reducer. So here, we are almost 3 times faster on reducer time. The thing that we need to discuss is: is the added complexity to the code worth the gain ? The overall gain is not stunning, but we do know that we don't spend most of the time in reducer. Still, this shaves off hundred ms on a high end laptop (so probably more on low end devices).
Attachment #8942892 - Flags: review?(bgrinstead) → review+
Comment on attachment 8942893 [details] Bug 1425577 - Do not create a new state for each message of a batch;. https://reviewboard.mozilla.org/r/213166/#review218980 Is there any way you could split this up so that the parts that aren't changing the behavior are in a separate changeset (i.e. test changes that pass without the rest of the patch, addMessages function, etc)? I think that would make it easier to review, but if that's going to be a pain or the parts can't effectively be split up then let me know and I'll go through it as-is. ::: devtools/client/webconsole/new-console-output/reducers/messages.js:60 (Diff revision 1) > - // Map of the form {messageId : networkInformation} > + // Map of the form {messageId : networkInformation} > - // `networkInformation` holds request, response, totalTime, ... > + // `networkInformation` holds request, response, totalTime, ... > - networkMessagesUpdateById: {}, > + networkMessagesUpdateById: {}, > -}, overrides)); > + }, overrides); > > -function addMessage(state, filtersState, prefsState, newMessage) { > + const wrap = freeze === true ? Object.freeze : (x) => x; Nit: the `wrap` function makes it slightly more difficult for me to follow and adds an extra function call for the non freeze state. Something like `return (freeze === true) ? Object.freeze(state) : state;` (or the same but out of a ternary if you prefer) would help.
Attachment #8942893 - Flags: review?(bgrinstead)
Comment on attachment 8943234 [details] Bug 1425577 - Fix typo;. https://reviewboard.mozilla.org/r/213492/#review219356 ::: commit-message-7024c:4 (Diff revision 1) > +Bug 1425577 - Fix typo;r=bgrins. > + > +currentGoup -> currentGroup. > +The typo was in the function parameter so we did not had bug Nit: 'not have a bug because of it'
Attachment #8943234 - Flags: review?(bgrinstead) → review+
Attachment #8943231 - Flags: review?(bgrinstead) → review+
Depends on: 1431327, 1417446
Attachment #8942892 - Attachment is obsolete: true
Attachment #8943231 - Attachment is obsolete: true
Attachment #8943234 - Attachment is obsolete: true
FYI, DAMP reports some wins on panelsInBackground. In this test, we call console.log while the webconsole is in background. React updates are paused, but not redux actions. So it quite well highlights your win here and ensure we will not regress it. https://treeherder.mozilla.org/perf.html#/comparesubtest?originalProject=try&originalRevision=9f498fc6a1eaa0b77c61a947edd5d88eee2d5bc2&newProject=try&newRevision=e7cf09086077c91d40fb6ae3948184bde879da6d&originalSignature=edaec66500db21d37602c99daa61ac983f21a6ac&newSignature=edaec66500db21d37602c99daa61ac983f21a6ac&showOnlyConfident=1&framework=1 complicated.reload -2.8% panelsInBackground.reload -10% + various other smaller win with medium confidence.
Attachment #8943233 - Attachment is obsolete: true
Attachment #8943233 - Flags: review?(bgrinstead)
Attachment #8943235 - Attachment is obsolete: true
Attachment #8943235 - Flags: review?(bgrinstead)
Attachment #8942893 - Attachment is obsolete: true
Attachment #8942893 - Flags: review?(bgrinstead)
Attachment #8943236 - Attachment is obsolete: true
Attachment #8943236 - Flags: review?(bgrinstead)
Brian, I changed things a bit in the last patch, and I think this looks much better. What we do now is that we clone the state before adding the new messages, and then mutate the cloned state in the addMessage function.
Comment on attachment 8943232 [details] Bug 1425577 - Do not clone the state for each message of a batch; . https://reviewboard.mozilla.org/r/213488/#review220904 Nice! ::: devtools/client/webconsole/new-console-output/reducers/messages.js:135 (Diff revision 4) > - } = getMessageVisibility(addedMessage, newState, filtersState); > + } = getMessageVisibility(addedMessage, state, filtersState); > > if (visible) { > - newState.visibleMessages = [...visibleMessages, newMessage.id]; > + state.visibleMessages.push(newMessage.id); > } else if (DEFAULT_FILTERS.includes(cause)) { > - newState.filteredMessagesCount = { > + state.filteredMessagesCount = { Nit: I believe this could be done without cloning filteredMessagesCount again - i.e. you could do something like: ``` state.filteredMessagesCount.global++; state.filteredMessages[cause]++; ```
Attachment #8943232 - Flags: review?(bgrinstead) → review+
Pushed by nchevobbe@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9a6d7da2f9b1 Do not clone the state for each message of a batch; r=bgrins.
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 60
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: