Closed
Bug 962968
Opened 11 years ago
Closed 11 years ago
Consider using SparseArray instead of HashMap for numeric keys
Categories
(Firefox for Android Graveyard :: General, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 29
People
(Reporter: rnewman, Assigned: lucasr)
References
Details
Attachments
(6 files)
4.66 KB,
patch
|
rnewman
:
review+
|
Details | Diff | Splinter Review |
5.57 KB,
patch
|
rnewman
:
review+
|
Details | Diff | Splinter Review |
1.91 KB,
patch
|
rnewman
:
review+
|
Details | Diff | Splinter Review |
3.36 KB,
patch
|
rnewman
:
review+
|
Details | Diff | Splinter Review |
3.11 KB,
patch
|
rnewman
:
review+
|
Details | Diff | Splinter Review |
1.38 KB,
patch
|
rnewman
:
review+
|
Details | Diff | Splinter Review |
----
# Use optimized data containers
Take advantage of optimized containers in the Android framework, such as SparseArray, SparseBooleanArray, and LongSparseArray. The generic HashMap implementation can be quite memory inefficient because it needs a separate entry object for every mapping. Additionally, the SparseArray classes are more efficient because they avoid the system's need to autobox the key and sometimes value (which creates yet another object or two per entry). And don't be afraid of dropping down to raw arrays when that makes sense.
----
mobile/android/base/favicons/decoders/ICODecoder.java
155: HashMap<Integer, IconDirectoryEntry> preferenceMap = new HashMap<Integer, IconDirectoryEntry>();
mobile/android/base/favicons/Favicons.java
65: private static final Map<Integer, LoadFaviconTask> sLoadTasks = Collections.synchronizedMap(new HashMap<Integer, LoadFaviconTask>());
mobile/android/base/GeckoJavaSampler.java
66: private Map<Integer,Sample[]> mSamples = new HashMap<Integer,Sample[]>();
mobile/android/base/home/PanelManager.java
54: private static final Map<Integer, RequestCallback> sCallbacks = Collections.synchronizedMap(new HashMap<Integer, RequestCallback>());
mobile/android/base/PrefsHelper.java
27: private static final Map<Integer, PrefHandler> sCallbacks = new HashMap<Integer, PrefHandler>();
mobile/android/base/util/ActivityResultHandlerMap.java
11: private Map<Integer, ActivityResultHandler> mMap = new HashMap<Integer, ActivityResultHandler>();
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → lucasr.at.mozilla
Assignee | ||
Comment 1•11 years ago
|
||
Assignee | ||
Comment 2•11 years ago
|
||
Assignee | ||
Comment 3•11 years ago
|
||
Assignee | ||
Comment 4•11 years ago
|
||
Assignee | ||
Comment 5•11 years ago
|
||
Assignee | ||
Comment 6•11 years ago
|
||
Assignee | ||
Updated•11 years ago
|
Attachment #8364416 -
Flags: review?(rnewman)
Assignee | ||
Updated•11 years ago
|
Attachment #8364418 -
Flags: review?(rnewman)
Assignee | ||
Updated•11 years ago
|
Attachment #8364419 -
Flags: review?(rnewman)
Assignee | ||
Updated•11 years ago
|
Attachment #8364420 -
Flags: review?(rnewman)
Assignee | ||
Updated•11 years ago
|
Attachment #8364421 -
Flags: review?(rnewman)
Assignee | ||
Updated•11 years ago
|
Attachment #8364417 -
Flags: review?(rnewman)
Reporter | ||
Updated•11 years ago
|
Attachment #8364416 -
Flags: review?(rnewman) → review+
Reporter | ||
Updated•11 years ago
|
Attachment #8364417 -
Flags: review?(rnewman) → review+
Reporter | ||
Comment 7•11 years ago
|
||
Comment on attachment 8364418 [details] [diff] [review]
Replace HashMap with SparseArray in GeckoJavaSampler (r=rnewman)
Review of attachment 8364418 [details] [diff] [review]:
-----------------------------------------------------------------
This is fine, but looking at the code it seems like GeckoJavaSampler should be rewritten to do something else -- ThreadLocals, maybe.
Attachment #8364418 -
Flags: review?(rnewman) → review+
Reporter | ||
Updated•11 years ago
|
Attachment #8364419 -
Flags: review?(rnewman) → review+
Reporter | ||
Updated•11 years ago
|
Attachment #8364420 -
Flags: review?(rnewman) → review+
Reporter | ||
Updated•11 years ago
|
Attachment #8364421 -
Flags: review?(rnewman) → review+
Reporter | ||
Comment 8•11 years ago
|
||
Thanks for tackling this so quickly, Lucas!
Now we'll see how much of a saving it is…
Status: NEW → ASSIGNED
Assignee | ||
Comment 9•11 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/65bfef117974
https://hg.mozilla.org/integration/fx-team/rev/4d79320f696e
https://hg.mozilla.org/integration/fx-team/rev/6944859764c3
https://hg.mozilla.org/integration/fx-team/rev/f8cb6d26dd7d
https://hg.mozilla.org/integration/fx-team/rev/533642b8d6df
https://hg.mozilla.org/integration/fx-team/rev/5d550701bd49
https://hg.mozilla.org/mozilla-central/rev/65bfef117974
https://hg.mozilla.org/mozilla-central/rev/4d79320f696e
https://hg.mozilla.org/mozilla-central/rev/6944859764c3
https://hg.mozilla.org/mozilla-central/rev/f8cb6d26dd7d
https://hg.mozilla.org/mozilla-central/rev/533642b8d6df
https://hg.mozilla.org/mozilla-central/rev/5d550701bd49
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 29
Any reason you stopped at those six examples, Richard? Ex: [1] [2]
On that note, we can probably be more explicit about setting initial sizes too, such as in [1] where I imagine we have 6 results.
[1]: https://mxr.mozilla.org/mozilla-central/source/mobile/android/base/home/TopSitesPanel.java#780
[2]: https://mxr.mozilla.org/mozilla-central/source/mobile/android/base/Tabs.java#50
Flags: needinfo?(rnewman)
Reporter | ||
Comment 12•11 years ago
|
||
(In reply to Michael Comella (:mcomella) from comment #11)
> Any reason you stopped at those six examples, Richard? Ex: [1] [2]
Didn't want to keep copy-pasting from grep :D
> On that note, we can probably be more explicit about setting initial sizes
> too, such as in [1] where I imagine we have 6 results.
Concur.
> [1]:
> https://mxr.mozilla.org/mozilla-central/source/mobile/android/base/home/
> TopSitesPanel.java#780
Err, this is a HashMap<String, Bitmap>…
> [2]:
> https://mxr.mozilla.org/mozilla-central/source/mobile/android/base/Tabs.
> java#50
HashMap is sometimes faster for lookup than SparseArray (depends on size); we should profile before attacking this kind of hot-path stuff.
File two follow-ups?
Flags: needinfo?(rnewman)
(In reply to Richard Newman [:rnewman] from comment #12)
> File two follow-ups?
bug 963863 - initialCapacity
bug 963873 - SparseArray (again)
Updated•4 years ago
|
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•