Use base::flat_map for base::Value dictionary storage.

This should give better memory locality and fewer allocations for our
workloads.

Most dictionaries are small and previously sorted (JSON Chrome writes
like preferences is written in keyed-order). This makes the flat_map
a better storage option because it avoids separate allocation for each
node and has better memory locality.

Performance from base_perftests JSONPerfTest.StressTest:
  Old:                        84,807ms
  Just replacing the storage: 70,363ms
  Optimizing JSON parser:     69,286ms

Primarily the improvement is in read performance (in creating the
dictionary nodes) but write performance is also improved slightly,
presumably due to better memory locality.

I did some manual checking for the creation of large dictionary values
(where this change may perform poorly) and did not find any in normal
Chrome runs other than the JSON parser and the value copy constructor.

Bringing flat_map.h into values_unittests.cc seems to confuse MSVC's
ADL resolution of swap and it gives errors about calling
flat_map::swap with base::Values. I wasn't able to figure out the
source of this problem. The test is really checking for operator= that
is generated by the default std::swap implementation (base::Value
doesn't specialize a swap so the "using std/swap" pattern for ADL is a
no-op), so I qualified the call to swap with a std::.

Review-Url: https://codereview.chromium.org/2807953002
Cr-Commit-Position: refs/heads/master@{#463371}


CrOS-Libchrome-Original-Commit: 8dd10d4011015ae6ce376a94666d56696e1ea7cd
4 files changed
tree: b494b669ab2b4921d5d5564832ab747b0ab3409d
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/