Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Issue 419973004: decorators.Cache Attach an unique id to objects (Closed)

Created:
6 years, 5 months ago by a.renevier
Modified:
6 years, 4 months ago
Reviewers:
dtu, tonyg
CC:
chromium-reviews, telemetry+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Project:
chromium
Visibility:
Public.

Description

decorators.Cache Attach an unique id to objects decorators.Cache keeps track of the function argument by getting their string representation. But it can happen that two objects have the same string representation, if they are created in two different functions (because they might be created in the same memory place). So, this patch checks the first argument of the function, and if it's possible to attribute to it an unique id, it does. Then, that unique id will be used as part of the hash key. Then, if the cached function is bound to two different objects, it will not consider those objects equal anymore. R=tonyg@chromium.org BUG=

Patch Set 1 #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+13 lines, -0 lines) Patch
M tools/telemetry/telemetry/decorators.py View 2 chunks +13 lines, -0 lines 1 comment Download

Messages

Total messages: 5 (0 generated)
a.renevier
6 years, 5 months ago (2014-07-25 20:44:25 UTC) #1
tonyg
https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/decorators.py File tools/telemetry/telemetry/decorators.py (right): https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/decorators.py#newcode31 tools/telemetry/telemetry/decorators.py:31: self.__CacheUniqueId = uuid.uuid4().hex Thanks for digging into this!! Looking ...
6 years, 5 months ago (2014-07-25 21:13:55 UTC) #2
a.renevier
On 2014/07/25 21:13:55, tonyg wrote: > https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/decorators.py > File tools/telemetry/telemetry/decorators.py (right): > > https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/decorators.py#newcode31 > ...
6 years, 5 months ago (2014-07-25 21:40:28 UTC) #3
tonyg
On 2014/07/25 21:40:28, a.renevier wrote: > On 2014/07/25 21:13:55, tonyg wrote: > > > https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/decorators.py ...
6 years, 4 months ago (2014-07-27 18:49:16 UTC) #4
a.renevier
6 years, 4 months ago (2014-08-04 23:28:32 UTC) #5
On 2014/07/27 18:49:16, tonyg wrote:
> On 2014/07/25 21:40:28, a.renevier wrote:
> > On 2014/07/25 21:13:55, tonyg wrote:
> > >
> >
>
https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/de...
> > > File tools/telemetry/telemetry/decorators.py (right):
> > > 
> > >
> >
>
https://codereview.chromium.org/419973004/diff/1/tools/telemetry/telemetry/de...
> > > tools/telemetry/telemetry/decorators.py:31: self.__CacheUniqueId =
> > > uuid.uuid4().hex
> > > Thanks for digging into this!!
> > > 
> > > Looking again at this code, I wonder whether the root problem is that the
> > > __cache lives on the function object instead of the instance. In addition
to
> > > causing the problem you noticed, it also seems prone to leaking memory.
> > 
> > I'm not sure how we can avoid that. The decorator (Cache function) is called
> > with the unbounded function. Also, at some places, the decorator is applied
to
> > function which are not parts of class
> > 
> > > 
> > > I wonder whether this (or something similar) works instead:
> > > 
> > > if args and isinstance(args[0], obj):
> > >   cache = args[0].__cache = {}
> > 
> > obj is the method, not the objet. So
> > 
> > > This also points out that we should really have a decorators_unittest.py
> > method.
> > > 
> > > Also, if it turns out that we can't move the cache to the right spot, a
> better
> > > way to get a unique ID would be id(args[0]).
> > 
> > This also doesn't work. The documentation says that by design, "Two objects
> with
> > non-overlapping lifetimes may have the same id() value."
> > And this is what happened in the situation I encountered. The two objects,
> > created in two different functions have the same id, and therefore, the same
> > string representation.
> > https://docs.python.org/2/library/functions.html#id
> 
> Here's something along the lines of what I had in mind:
> https://codereview.chromium.org/425613002/
> 
> LMK what you think.

This patch seems better than mine. Should I close the issue?

Powered by Google App Engine
This is Rietveld 408576698