Eliminate unnecessary string concatenations in ImageCacheKey::ComputeHash

RESOLVED FIXED in Firefox 51

Status

()

P3
normal
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: aosmond, Assigned: aosmond)

Tracking

unspecified
mozilla53
Points:
---

Firefox Tracking Flags

(firefox51 fixed, firefox52 fixed, firefox53 fixed)

Details

(Whiteboard: gfx-noted, crash signature)

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

2 years ago
Hashing several strings appended together, and hashing them individually should result in the same value, except the latter is a much cheaper option.

http://searchfox.org/mozilla-central/rev/b4e6fa3527436bdbcd9dd2e1982382fe423431f3/image/ImageCacheKey.cpp#158

This allow triggers a malloc, which shows up in crash signatures, such as:

https://crash-stats.mozilla.com/report/index/77317c14-819d-4853-99ac-7bcaf2161118

The malloc is so big (presumably) because the URI spec can be quite large if it is just a base64 encoded image instead of a normal URL.
(Assignee)

Updated

2 years ago
Assignee: nobody → aosmond
Status: NEW → ASSIGNED
Priority: -- → P3
Whiteboard: gfx-noted
(Assignee)

Updated

2 years ago
Crash Signature: [@ OOM | large | NS_ABORT_OOM | nsACString_internal::Assign | mozilla::image::ImageCacheKey::ImageCacheKey ]
(Assignee)

Comment 1

2 years ago
Created attachment 8814245 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v1

try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=dec4057d18498db22bed7480dd730c991746da70
Attachment #8814245 - Flags: review?(tnikkel)
(Assignee)

Updated

2 years ago
status-firefox51: --- → affected
status-firefox52: --- → affected
status-firefox53: --- → affected
Comment on attachment 8814245 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v1

Nice!

ImageURL::ComputeHash isn't a generic function, but rather specific to ImageCacheKey. So maybe make it private and mark ImageCacheKey as a friend class?
Attachment #8814245 - Flags: review?(tnikkel) → review+
(Assignee)

Comment 3

2 years ago
Created attachment 8814389 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v2 [carries r=tnikkel]

Incorporate review feedback.
Attachment #8814245 - Attachment is obsolete: true
Attachment #8814389 - Flags: review+

Comment 4

2 years ago
Pushed by aosmond@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/b8cdb59ac18b
Avoid string concatenation when computing the hash for ImageCacheKey. r=tnikkel

Comment 5

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/b8cdb59ac18b
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox53: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
(Assignee)

Comment 6

2 years ago
Comment on attachment 8814389 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v2 [carries r=tnikkel]

Approval Request Comment
[Feature/regressing bug #]: N/A
[User impact if declined]: May crash in low memory conditions.
[Describe test coverage new/current, TreeHerder]: The crash itself has only been observed in crash reports, not easily reproducible. However the crash occurs on a success path used every time an image is loaded and is thus well exercised by existing mochi/web-platorm/reftests.
[Risks and why]: Minimal, there was no functional change, only the need for some temporary allocations on the heap was removed.
[String/UUID change made/needed]: N/A
Attachment #8814389 - Flags: approval-mozilla-aurora?
(Assignee)

Comment 7

2 years ago
Comment on attachment 8814389 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v2 [carries r=tnikkel]

Approval Request Comment
[Feature/regressing bug #]: N/A
[User impact if declined]: May crash in low memory conditions.
[Describe test coverage new/current, TreeHerder]: The crash itself has only been observed in crash reports, not easily reproducible. However the crash occurs on a success path used every time an image is loaded and is thus well exercised by existing mochi/web-platorm/reftests.
[Risks and why]: Minimal, there was no functional change, only the need for some temporary allocations on the heap was removed.
[String/UUID change made/needed]: N/A
Attachment #8814389 - Flags: approval-mozilla-beta?
Comment on attachment 8814389 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v2 [carries r=tnikkel]

reduce risk of OOM, take in aurora52
Attachment #8814389 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+

Comment 9

2 years ago
bugherderuplift
https://hg.mozilla.org/releases/mozilla-aurora/rev/35d579c4ff1e
status-firefox52: affected → fixed
Comment on attachment 8814389 [details] [diff] [review]
Remove string concat in ImageCacheKey::ComputeHash, v2 [carries r=tnikkel]

Fix a crash. Beta51+. Should be in 51 beta 5.
Attachment #8814389 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Comment 11

2 years ago
bugherderuplift
https://hg.mozilla.org/releases/mozilla-beta/rev/110c796d4372
status-firefox51: affected → fixed
You need to log in before you can comment on or make changes to this bug.