Atomize strings when adding to Map (as a key) or Set

RESOLVED FIXED in mozilla17

Status

()

Core
JavaScript Engine
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: jorendorff, Assigned: jorendorff)

Tracking

Other Branch
mozilla17
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [js:t])

Attachments

(2 attachments)

(Assignee)

Description

5 years ago
HashableValue::setValue is a convenient place to do this.

Tradeoffs:

- Atomizing takes time.
+ Without atomizing, every hash table lookup with a string key
  must take time proportional to the length of the string.
  With atomizing, there are some cases where lookup can be much faster.
+ With atomizing, all comparisons are simple 64-bit comparisons.
+ With atomizing, HashableValue::hash() is always fast, so growing a table
  can be fast even if there are long string keys.
+ With atomizing, HashableValue::hash() is so fast that caching a hash code
  for each entry in the hash table is pointless. (We currently do not cache
  hash codes anyway; we're just slow.)
- Atomizing can make extra copies of strings.
+ Atomizing can common up strings, saving memory.
- Atomizing makes strings in the atom compartment that won't be collected
  until the next full (runtime-wide) GC.

I think we should atomize.

(At the same time--I think HashableValue::hash()'s last line can be a little simpler given the changes to ScrambleHashCode in bug 743107. Not sure.)
(Assignee)

Updated

5 years ago
Depends on: 743107
Whiteboard: [js:t]
(Assignee)

Comment 1

5 years ago
Created attachment 638357 [details] [diff] [review]
part 0 - trivial: switch to // comments
Assignee: general → jorendorff
Attachment #638357 - Flags: review?(luke)
(Assignee)

Comment 2

5 years ago
Created attachment 638358 [details] [diff] [review]
part 1 - atomize, v1
Attachment #638358 - Flags: review?(luke)

Updated

5 years ago
Attachment #638357 - Flags: review?(luke) → review+

Comment 3

5 years ago
Comment on attachment 638358 [details] [diff] [review]
part 1 - atomize, v1

Nice
Attachment #638358 - Flags: review?(luke) → review+
(Assignee)

Comment 4

5 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/926876345186
https://hg.mozilla.org/integration/mozilla-inbound/rev/aec1ad4171a1
https://hg.mozilla.org/mozilla-central/rev/926876345186
https://hg.mozilla.org/mozilla-central/rev/aec1ad4171a1
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla16
I was backing out a number of patches in the js land, and unfortunately this patch caused a number of merge conflicts which I did not trust myself to resolve.  Therefore, I had to back it out.  Please reland after fixing the conflicts resulting from the backouts.  Thanks, and apologies for the inconvenience.

Backout changeset:
https://hg.mozilla.org/mozilla-central/rev/f6bdb7fc663f
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(Assignee)

Comment 7

5 years ago
Relanded. https://hg.mozilla.org/integration/mozilla-inbound/rev/e5345853fdac
Target Milestone: mozilla16 → mozilla17
https://hg.mozilla.org/mozilla-central/rev/e5345853fdac
Status: REOPENED → RESOLVED
Last Resolved: 5 years ago5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.