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

Issue 1610733002: Store PreRead options obtained from the registry in a global variable. (Closed)

Created:
4 years, 11 months ago by fdoray
Modified:
4 years, 11 months ago
Reviewers:
gab, grt (UTC plus 2)
CC:
chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Store PreRead options obtained from the registry in a global variable. Instead of reading PreRead options from the registry every time they are needed, read them once and store them in a global variable. This optimization isn't immediately useful as PreRead options are currently read only once per process. However, with the upcoming /prefetch:# experiment, the browser process will need the PreRead options every time it launches a process. This CL also has these benefits: - The caller of GetPreReadOptions doesn't need to know the product registry path. This will allow content to get the PreRead options to decide whether it should use a /prefetch:# switch when launching a process. - The PreRead options are returned as a bit field instead of by setting multiple booleans. This will facilitate the addition of new PreRead options. BUG=577698 Committed: https://crrev.com/dee064299d3b3a13d5cc35f219d87d6a8478f227 Cr-Commit-Position: refs/heads/master@{#370805}

Patch Set 1 #

Total comments: 8

Patch Set 2 : address comments from gab #5 #

Patch Set 3 : self-review #

Patch Set 4 : self-review #

Total comments: 17

Patch Set 5 : address comments from grt #8 #

Patch Set 6 : self-review #

Patch Set 7 : don't return a const ref #

Unified diffs Side-by-side diffs Delta from patch set Stats (+54 lines, -44 lines) Patch
M chrome/app/main_dll_loader_win.cc View 1 2 3 4 5 2 chunks +10 lines, -14 lines 0 comments Download
M components/startup_metric_utils/common/pre_read_field_trial_utils_win.h View 1 2 3 4 6 1 chunk +23 lines, -13 lines 0 comments Download
M components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc View 1 2 3 4 6 3 chunks +21 lines, -17 lines 0 comments Download

Dependent Patchsets:

Messages

Total messages: 21 (8 generated)
fdoray
gab@ and grt@: Can you review this CL? Thanks.
4 years, 11 months ago (2016-01-20 19:05:47 UTC) #3
gab
Comments below. I'd say change title/description: to me this is more about early one-time optimization ...
4 years, 11 months ago (2016-01-20 20:09:40 UTC) #5
fdoray
gab@: Can you take another look? grt@: Can you review this CL? https://codereview.chromium.org/1610733002/diff/1/chrome/app/main_dll_loader_win.cc File chrome/app/main_dll_loader_win.cc ...
4 years, 11 months ago (2016-01-20 21:58:53 UTC) #7
grt (UTC plus 2)
https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loader_win.cc File chrome/app/main_dll_loader_win.cc (right): https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loader_win.cc#newcode72 chrome/app/main_dll_loader_win.cc:72: if (!(pre_read_options & startup_metric_utils::PRE_READ_OPTION_NO_PRE_READ)) { i think this would ...
4 years, 11 months ago (2016-01-21 04:24:00 UTC) #8
fdoray
grt@: Can you take another look? Thanks. https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loader_win.cc File chrome/app/main_dll_loader_win.cc (right): https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loader_win.cc#newcode72 chrome/app/main_dll_loader_win.cc:72: if (!(pre_read_options ...
4 years, 11 months ago (2016-01-21 16:04:17 UTC) #9
grt (UTC plus 2)
lgtm provided that the options struct is returned by value rather than by constref. https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loader_win.cc ...
4 years, 11 months ago (2016-01-21 18:15:42 UTC) #10
gab
lgtm Too bad that we can't DCHECK for initialization. I guess this also means that ...
4 years, 11 months ago (2016-01-21 19:49:27 UTC) #11
fdoray
All done. Committing. gab@: You're right, this code doesn't work correctly in a component build ...
4 years, 11 months ago (2016-01-21 21:16:08 UTC) #12
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1610733002/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1610733002/120001
4 years, 11 months ago (2016-01-21 21:17:22 UTC) #15
grt (UTC plus 2)
On 2016/01/21 19:49:27, gab wrote: > lgtm > > Too bad that we can't DCHECK ...
4 years, 11 months ago (2016-01-21 21:24:12 UTC) #16
commit-bot: I haz the power
Committed patchset #7 (id:120001)
4 years, 11 months ago (2016-01-21 22:14:29 UTC) #18
commit-bot: I haz the power
Patchset 7 (id:??) landed as https://crrev.com/dee064299d3b3a13d5cc35f219d87d6a8478f227 Cr-Commit-Position: refs/heads/master@{#370805}
4 years, 11 months ago (2016-01-21 22:15:57 UTC) #20
gab
4 years, 11 months ago (2016-01-22 20:14:37 UTC) #21
Message was sent while issue was closed.
On 2016/01/21 21:24:12, grt wrote:
> On 2016/01/21 19:49:27, gab wrote:
> > lgtm
> > 
> > Too bad that we can't DCHECK for initialization. I guess this also means
that
> > this code doesn't work in component builds? (that's a pain for testing isn't
> > it?)
> > 
> >
>
https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loa...
> > File chrome/app/main_dll_loader_win.cc (right):
> > 
> >
>
https://codereview.chromium.org/1610733002/diff/60001/chrome/app/main_dll_loa...
> > chrome/app/main_dll_loader_win.cc:72: if (!(pre_read_options &
> > startup_metric_utils::PRE_READ_OPTION_NO_PRE_READ)) {
> > On 2016/01/21 18:15:42, grt wrote:
> > > On 2016/01/21 16:04:16, fdoray wrote:
> > > > On 2016/01/21 04:24:00, grt wrote:
> > > > > i think this would be easier to read if pre_read_option was actually
> > > something
> > > > > like:
> > > > > struct PreReadOptions {
> > > > >   bool no_pre_read : 1;
> > > > >   bool high_priority : 1;
> > > > >   ...
> > > > > };
> > > > > wdyt?
> > > > 
> > > > Done. Except that I didn't use :1 in the struct -> if I did, it wouldn't
> be
> > > > possible to take the address of members like I'm doing now in
> > > > InitializePreReadOptions [1]. If you really want me to use :1, I could
> > change
> > > > InitializePreReadOptions so that it doesn't need to take the address of
> > > members.
> > > > 
> > > > [1] https://msdn.microsoft.com/en-us/library/yszfawxh.aspx
> > > 
> > > I find the data-driven loop in InitializePreReadOptions interesting, but
not
> > so
> > > compelling that it should dictate the overall interface. Four calls to
> ReadDW
> > > (or a tiny helper function) is quite clear, whereas the loop takes a
little
> > > reading to validate. I'm okay with it as-is, just pointing out that a
clean
> > > interface is more important than a clever implementation. :-)
> > > 
> > > If you'd like to keep the loop, then avoiding the bitfield is fine. In
> either
> > > case, I think the struct should be passed by value rather than by
reference.
> > The
> > > compiler is potentially smart enough to pack the four bools into a 32-bit
> int.
> > 
> > FWIW, I think the loop is actually more readable than duplicating the same
5-6
> > lines of code 4+ times.
> 
> I strongly disagree. The following is less code and, imo, easier to read:
> 
> bool ReadBool(const base::win::RegKey& key, const base::char16* name) {
>   DWORD value = 0;
>   return key.ReadValueDW(name, &value) == ERROR_SUCCESS && value != 0;
> }
> 
> void InitializePreReadOptions(const base::string16& product_registry_path) {
>   ...
>   option.no_pre_read = ReadBool(key, kNoPreReadVariationName);
>   option.high_priority = ReadBool(key, kHighPriorityVariationName);
>   option.only_if_cold = ReadBool(key, kOnlyIfColdVariationName);
>   option.prefetch_virtual_memory = ReadBool(key,
> kPrefetchVirtualMemoryVariationName);
>   ...

I like that. I guess the loop is trying to keep the body of this helper in the
method but it's fine to take it out.

I'm happy either way with slight preference for your suggestion now that I see
it.

> 
> 
> > The loop approach says "here's what I'm doing" from
> > "this data" instead of having to make sure that the duplicated code has its
> own
> > variable names (it could re-use but then you lose the DCHECKs) and properly
> > replaces all bits of the duplicated code to point to its own things.
> 
> It also hid a subtle bug that you missed in your review. :-)

You mean |= instead of &= bug? Good catch but that bug would have been just as
likely by using a helper method (provided we still used bitfields; of course no
bit fields => no bit manipulation bug regardless of loop or not :-)).

> 
> > I value compact/readable code more than saving a few bits (especially if the
> > compiler is likely to optimize it out anyways).
> 
> I agree that saving bits isn't a priority, but a clean interface is.

Powered by Google App Engine
This is Rietveld 408576698