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

Issue 1156923005: Cache vectors to avoid heap allocations on each message pump iteration. (Closed)

Created:
5 years, 6 months ago by Anand Mistry (off Chromium)
Modified:
5 years, 6 months ago
Reviewers:
viettrungluu, qsr
CC:
abarth-chromium, Aaron Boodman, ben+mojo_chromium.org, chrome-apps-syd-reviews_chromium.org, darin (slow to review), gregsimon, mojo-reviews_chromium.org, qsr+mojo_chromium.org, viettrungluu+watch_chromium.org, yzshen+watch_chromium.org
Base URL:
https://github.com/domokit/mojo.git@master
Target Ref:
refs/heads/master
Project:
mojo
Visibility:
Public.

Description

Cache vectors to avoid heap allocations on each message pump iteration. In Chrome, MessagePumpMojo::DoInternalWork causes ~50,000 heap allocations when loading The Verge. This change drops that to ~5000, measured on a debug build. On each loop, WaitState has two vectors which are allocated, and resized multiple times. Caching the WaitState between iterations largely eliminates those allocations. The story with |cloned_handlers| is a bit different. HandleToHandler is a hash map, and GCC's implementation does a heap allocation for every new element added. That means at least handlers_.size() allocations on every iteration. This replaces that with a single allocaiton in a vector. Chrome's MojoChannelPerfTest doesn't show a significant improvement. Showing (min/max/mean/median/stddev) in ms per run over 10 runs: IPC_Channel_Perf_50000x_12 before 1016 1046 1030 1030 7.5 after 998 1032 1013 1011 10.3 IPC_ChannelProxy_Perf_50000x_12 before 1804 3809 2633 2486 637 after 2019 3690 2625 2413 489 And in case you're wondering, the remaining ~5000 heap allocations are mostly in mojo::system::Core::WaitMany(). R=qsr@chromium.org Committed: https://chromium.googlesource.com/external/mojo/+/ecf671725e139e27d8e07073e0722d10829e28c7

Patch Set 1 #

Total comments: 10

Patch Set 2 : Review comments. #

Patch Set 3 : Review round 2. #

Patch Set 4 : Rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+57 lines, -18 lines) Patch
M mojo/common/message_pump_mojo.h View 3 chunks +4 lines, -1 line 0 comments Download
M mojo/common/message_pump_mojo.cc View 1 2 6 chunks +53 lines, -17 lines 0 comments Download

Messages

Total messages: 13 (3 generated)
Anand Mistry (off Chromium)
abarth@chromium.org, qsr@chromium.org: Sending to you since you made the last significant change to this code. ...
5 years, 6 months ago (2015-05-28 08:22:19 UTC) #2
qsr
On 2015/05/28 08:22:19, Anand Mistry wrote: > mailto:abarth@chromium.org, mailto:qsr@chromium.org: Sending to you since you made ...
5 years, 6 months ago (2015-05-28 09:33:37 UTC) #4
qsr
https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc File mojo/common/message_pump_mojo.cc (right): https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc#newcode225 mojo/common/message_pump_mojo.cc:225: 2 * run_state_->wait_state->wait_signals.size()) { Not sure the || is ...
5 years, 6 months ago (2015-05-28 09:33:48 UTC) #5
viettrungluu
On 2015/05/28 09:33:37, qsr wrote: > On 2015/05/28 08:22:19, Anand Mistry wrote: > > mailto:abarth@chromium.org, ...
5 years, 6 months ago (2015-05-28 17:26:54 UTC) #6
Anand Mistry (off Chromium)
https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc File mojo/common/message_pump_mojo.cc (right): https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc#newcode225 mojo/common/message_pump_mojo.cc:225: 2 * run_state_->wait_state->wait_signals.size()) { On 2015/05/28 09:33:48, qsr wrote: ...
5 years, 6 months ago (2015-05-28 23:27:45 UTC) #7
abarth-chromium
I'm not the right reviewer for this change.
5 years, 6 months ago (2015-05-28 23:32:17 UTC) #9
qsr
LGTM with optional nit. https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc File mojo/common/message_pump_mojo.cc (right): https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc#newcode295 mojo/common/message_pump_mojo.cc:295: wait_state->wait_signals.clear(); On 2015/05/28 23:27:45, Anand ...
5 years, 6 months ago (2015-05-29 07:56:08 UTC) #10
Anand Mistry (off Chromium)
https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc File mojo/common/message_pump_mojo.cc (right): https://codereview.chromium.org/1156923005/diff/1/mojo/common/message_pump_mojo.cc#newcode295 mojo/common/message_pump_mojo.cc:295: wait_state->wait_signals.clear(); On 2015/05/29 07:56:08, qsr wrote: > On 2015/05/28 ...
5 years, 6 months ago (2015-05-29 09:00:57 UTC) #11
Anand Mistry (off Chromium)
vtl: Any comments?
5 years, 6 months ago (2015-06-01 04:21:18 UTC) #12
Anand Mistry (off Chromium)
5 years, 6 months ago (2015-06-03 03:07:49 UTC) #13
Message was sent while issue was closed.
Committed patchset #4 (id:60001) manually as
ecf671725e139e27d8e07073e0722d10829e28c7 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698