chen870647924 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Make ReferenceEntries with StrongValueReferences less heavy-weight #878

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, a ReferenceEntry like a WeakEntry in a Cache is quite heavy-weight 
(in terms of memory-consumption), even if it strongly refers to its value. (I 
expect weak keys/strong values to be a very common pattern.) This is because 
the (on my machine) 40 bytes WeakEntry refers to another 16 byte 
StrongValueReference instead of just storing the reference "unboxed" in the 
WeakEntry.

One way to address this, without breaking the interface of ReferenceEntry, 
would be to add a specialized WeakEntryWithStrongValue (name could arguably be 
improved ;-) which implements the ValueReference interface itself. Its 
getValueReference() method would then simply return "this".

Original issue reported on code.google.com by s...@st.informatik.tu-darmstadt.de on 20 Jan 2012 at 10:28

GoogleCodeExporter commented 9 years ago

Original comment by wasserman.louis on 20 Jan 2012 at 4:04

GoogleCodeExporter commented 9 years ago
I'd be interested in doing this, though I might request some help from Dmitris 
and the memory analysis on Cache that he's already done.

Original comment by wasserman.louis on 20 Feb 2012 at 5:15

GoogleCodeExporter commented 9 years ago
Sounds about right, 40 + 16 + a reference (aligned) holding this structure = 64 
bytes that I've been measuring. Without looking the code, I vaguely recall a 
TODO note calling out this possibility, is that right? 

But the important detail is whether the cost can drop to 48 bytes, rather than 
56. One would represent a 25% reduction for these caches, the other 'just' 
12.5%, which would be able to justify less extra code complexity than the 
former.

This is a case where an external patch would help. If I'm given a patch, I can 
easily tell which is the case, or one can use an external memory measuring 
tool, or other cruder means to measure the space reduction. And Charles would 
be able, at a glance, to see what kind of complexity we're talking.

Original comment by jim.andreou on 20 Feb 2012 at 11:05

GoogleCodeExporter commented 9 years ago
I will attempt a patch, and let y'all know if I encounter any particular 
difficulties.

Original comment by wasserman.louis on 20 Feb 2012 at 11:07

GoogleCodeExporter commented 9 years ago
This is somewhat more complex than I'd hoped.  I will continue working on it, 
but it'll require a fair amount of refactoring.

Original comment by wasserman.louis on 23 Feb 2012 at 9:25

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 12 Mar 2013 at 6:43

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:14

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08