[New-bugs-announce] [issue18594] C accelerator for collections.Counter is slow

Stefan Behnel report at bugs.python.org
Tue Jul 30 08:49:20 CEST 2013


New submission from Stefan Behnel:

The C accelerator for the collections.Counter class (_count_elements() in _collections.c) is slower than the pure Python versions for data that has many unique entries. This is because the fast path for dicts is not taken (Counter is a subtype of dict) and the slower fallback path raises exceptions for each value that wasn't previously seen. This can apparently make it slower than calling get() on Python side.

My suggestion is to drop the fallback path from the accelerator completely and to only call the C function when it's safe to use it, e.g. when "type(self) is Counter" and not a subclass.

----------
components: Library (Lib)
messages: 193914
nosy: scoder, serhiy.storchaka
priority: normal
severity: normal
status: open
title: C accelerator for collections.Counter is slow
type: performance
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18594>
_______________________________________


More information about the New-bugs-announce mailing list