New issue
Advanced search Search tips

Issue 719054 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug
Team-Accessibility



Sign in to add a comment

AccessibilityEnumMap constructor is large, does many allocations

Project Member Reported by brucedaw...@chromium.org, May 5 2017

Issue description

While 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.

 
Labels: Performance-Size
Adding appropriate label. This is a minor issue, but it should be fairly straightforward to change this function to make it much smaller while also significantly reducing the number of allocations (thus reducing private bytes), although the private-byte reduction is made less critical by the fact that this function is often not called.
Owner: dmazz...@chromium.org
Status: Assigned (was: Untriaged)
Hey Dominic, this looks like low hanging fruit for someone on your team. Mind taking a look and helping triage?
Status: Started (was: Assigned)
https://chromium-review.googlesource.com/c/chromium/src/+/638916

Project Member

Comment 4 by bugdroid1@chromium.org, 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

Status: Fixed (was: Started)

Sign in to add a comment