[issue5730] setdefault speedup

2012-05-16 Thread Antoine Pitrou
Antoine Pitrou added the comment: Out of date, fixed in #13521. -- nosy: +pitrou resolution: -> duplicate status: open -> closed superseder: -> Make dict.setdefault() atomic ___ Python tracker ___

[issue5730] setdefault speedup

2009-04-13 Thread Dan Schult
Dan Schult added the comment: Thank you... I stand corrected That's actually very helpful! Of course using defdict makes the default assignment take two hashes, two lookups, an attribute/function lookup (__missing__) and the extra function call, plus doesn't allow arguments to the objec

[issue5730] setdefault speedup

2009-04-13 Thread Martin v. Löwis
Martin v. Löwis added the comment: > The missing key reports the default object, but doesn't set that key > or value object in the dict. That's just not true. Re-read the line in the doc string where it puts the default value into the dict, under the key being accessed. > For example, to rep

[issue5730] setdefault speedup

2009-04-12 Thread Dan Schult
Dan Schult added the comment: On Apr 11, 2009, at 8:15 AM, Martin v. Löwis @psf.upfronthosting.co.za @psf.upfronthosting.co.za> wrote: > Martin v. Löwis added the comment: > >> By the way, defaultdict is NOT like setdefault--it is like get(). >> Missing entries do no get set. > > Why do you

[issue5730] setdefault speedup

2009-04-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: I would support fixing the double call to PyObject_Hash(). For user defined classes with their own __hash__ methods, this is by far the slowest part of the operation. > from my perspective creating an internal SetItem adds another > function handling the da

[issue5730] setdefault speedup

2009-04-11 Thread Martin v. Löwis
Martin v. Löwis added the comment: > By the way, defaultdict is NOT like setdefault--it is like get(). > Missing entries do no get set. Why do you say that? __missing__(...) __missing__(key) # Called by __getitem__ for missing key; pseudo-code: if self.default_factory is None: raise Ke

[issue5730] setdefault speedup

2009-04-09 Thread Dan Schult
Dan Schult added the comment: Benchmarks: Upon trying cooked up examples, I do not notice any speedup beyond 5-10%. Seems like function calling time swamps everything for small examples with fast hashes. I don't have a handy dandy example with long hash times or long lookup times. That's what

[issue5730] setdefault speedup

2009-04-09 Thread Martin v. Löwis
Martin v. Löwis added the comment: > Martin, any thoughts? The same as always: Dan, do you have any benchmarks that demonstrate the speedup? Looking at the usage of setdefault in the standard library, it seems that it's most of the time either an interned string, or an object hashed by memory

[issue5730] setdefault speedup

2009-04-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: Inlining code saves work but breaks the effort to minimize the number of functions that have direct access to the underlying data structure. The performance of setdefault() is hard to improve in real apps because the cost of instantiating the default object

[issue5730] setdefault speedup

2009-04-09 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger nosy: +rhettinger versions: -Python 2.6, Python 3.0 ___ Python tracker ___

[issue5730] setdefault speedup

2009-04-09 Thread Dan Schult
Changes by Dan Schult : -- keywords: +patch Added file: http://bugs.python.org/file13665/dict_setdefault.patch ___ Python tracker ___ _

[issue5730] setdefault speedup

2009-04-09 Thread Dan Schult
New submission from Dan Schult : In the depths of dictobject.c one can see that dict_setdefault uses two identical calls to PyObject_Hash and ma_lookup. The first to see if the item is in the dict, the second (only if key is not present) to add the item to the dict. This second lookup (and h