[issue38278] Need a more efficient way to perform dict.get(key, default)

2021-07-13 Thread Inada Naoki
Change by Inada Naoki : -- nosy: +methane ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python

[issue38278] Need a more efficient way to perform dict.get(key, default)

2021-07-13 Thread Irit Katriel
Irit Katriel added the comment: > Was LOAD_METHOD optimized for builtin methods? Maybe this can be done with specialization. -- nosy: +Mark.Shannon, gvanrossum, iritkatriel ___ Python tracker _

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Was LOAD_METHOD optimized for builtin methods? -- ___ Python tracker ___ ___ Python-bugs-list m

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-26 Thread Tahia K
Change by Tahia K : -- nosy: +ta1hia ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-25 Thread STINNER Victor
STINNER Victor added the comment: I also suggest you to not focus on such micro-benchmarks. It's not relevant to make a whole application faster. Use PyPy if you care about performances. PyPy has a very efficient implementation for dictionary and it's JIT compiler can go way further than CPy

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-25 Thread Ben Spiller
Ben Spiller added the comment: Thanks... yep I realise method calls are slower than operators, am hoping we can still find a cunning way to speed up this use case nonetheless. :D For example by having a configuration option on dict (or making a new subclass) that gives the (speedy!) [] opera

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-25 Thread STINNER Victor
STINNER Victor added the comment: > Lots of solutions are possible - maybe some kind of peephole optimization to > make dict.get() itself perform similarly to the [] operator, or if that's > challenging perhaps providing a class or option that behaves like defaultdict > but without the auto-

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-25 Thread STINNER Victor
STINNER Victor added the comment: >python -m timeit -s "import collections; d=collections.defaultdict(lambda: >None); d['abc']=123; " "x=d['XXX']" 500 loops, best of 5: 34.3 nsec per loop This benchmark is not a fair comparison: the 'XXX' key is created at the first access. In short, thi

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-25 Thread STINNER Victor
STINNER Victor added the comment: dict.get() is a method call wheras "key in dict" and "dict[key]" are operators. Method calls are still slower than operators, even after past optimizations. For example, when dict.get was converted to METH_FASTCALL, it was around 20 ns faster: https://vstinn

[issue38278] Need a more efficient way to perform dict.get(key, default)

2019-09-25 Thread Ben Spiller
New submission from Ben Spiller : In performance-critical python code, it's quite common to need to get an item from a dictionary, falling back on a default (e.g. None, 0 etc) if it doesn't yet exist. The obvious way to do this based on the documentation is to call the dict.get() method: > p