Issue metadata
Sign in to add a comment
|
AccessibilityEnumMap constructor is large, does many allocations |
||||||||||||||||||||||
Issue descriptionWhile investigating an unrelated binary size regression ( crbug.com/714841 ) I noticed that the AccessibilityEnumMap constructor in content\browser\accessibility\accessibility_tree_formatter_utils_win.cc was quite large - about 13-14 KB. When inspecting the code I noticed that it adds ~230 int/std::string16 pairs to std::maps which means that it does about 460 memory allocations. I think that the code size could be drastically reduced by having a static array of int/L"" pairs, and then having a loop that adds this data to the associative arrays. That is, instead of the current ~230 calls to std::map::operator= it could be reduced to five, or perhaps just one. The number of allocations is also a concern. Currently each entry allocates a std::map node and also allocates (unless the small-string optimization applies) memory for the string stored in the base::string16 object. Half of the allocations can easily be avoided by using base::StringPiece16 instead of base::string16. I made a proof-of-concept change that does this, uploaded to crrev.com/2864773002. The remaining allocations could be avoided by using flat_map instead of map, which also gives faster lookups. These two techniques could be combined. Alternately, the static array of int/L"" pairs could be used directly. This would just require sorting it in the constructor and doing a binary search over the array. With a helper function this would add essentially no additional complexity, although it would mean that the static array of int/L"" pairs could not be const. The ultimate version would be to have the static array of int/L"" pairs be initialized in sorted order, thus getting the absolute minimum constructor size and data size, while still giving faster lookups than the current std::map solution. For the last two solutions it might be better to have int/StringPiece16 pairs.
,
Aug 25 2017
Hey Dominic, this looks like low hanging fruit for someone on your team. Mind taking a look and helping triage?
,
Aug 28 2017
,
Aug 30 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/b911e5c52aad32df95f5e605bfcca49df6ee2708 commit b911e5c52aad32df95f5e605bfcca49df6ee2708 Author: Dominic Mazzoni <dmazzoni@chromium.org> Date: Wed Aug 30 17:56:19 2017 Optimize use of maps in accessibility_tree_formatter_utils_win.cc Avoid generating so much code to insert into maps, and avoid allocating so many strings. Bug: 719054 Change-Id: I20b413dbfe6ae37078bbacbd8cc16447e75d98dd Reviewed-on: https://chromium-review.googlesource.com/638916 Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org> Reviewed-by: Bruce Dawson <brucedawson@chromium.org> Cr-Commit-Position: refs/heads/master@{#498531} [modify] https://crrev.com/b911e5c52aad32df95f5e605bfcca49df6ee2708/content/browser/accessibility/accessibility_tree_formatter_utils_win.cc
,
Aug 30 2017
|
|||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||
Comment 1 by brucedaw...@chromium.org
, Jun 9 2017