cpython/Objects
Tim Peters dea48ec581 SF patch #425242: Patch which "inlines" small dictionaries.
The idea is Marc-Andre Lemburg's, the implementation is Tim's.
Add a new ma_smalltable member to dictobjects, an embedded vector of
MINSIZE (8) dictentry structs.  Short course is that this lets us avoid
additional malloc(s) for dicts with no more than 5 entries.

The changes are widespread but mostly small.

Long course:  WRT speed, all scalar operations (getitem, setitem, delitem)
on non-empty dicts benefit from no longer needing NULL-pointer checks
(ma_table is never NULL anymore).  Bulk operations (copy, update, resize,
clearing slots during dealloc) benefit in some cases from now looping
on the ma_fill count rather than on ma_size, but that was an unexpected
benefit:  the original reason to loop on ma_fill was to let bulk
operations on empty dicts end quickly (since the NULL-pointer checks
went away, empty dicts aren't special-cased any more).

Special considerations:

For dicts that remain empty, this change is a lose on two counts:
the dict object contains 8 new dictentry slots now that weren't
needed before, and dict object creation also spends time memset'ing
these doomed-to-be-unsused slots to NULLs.

For dicts with one or two entries that never get larger than 2, it's
a mix:  a malloc()/free() pair is no longer needed, and the 2-entry case
gets to use 8 slots (instead of 4) thus decreasing the chance of
collision.  Against that, dict object creation spends time memset'ing
4 slots that aren't strictly needed in this case.

For dicts with 3 through 5 entries that never get larger than 5, it's a
pure win:  the dict is created with all the space they need, and they
never need to resize.  Before they suffered two malloc()/free() calls,
plus 1 dict resize, to get enough space.  In addition, the 8-slot
table they ended with consumed more memory overall, because of the
hidden overhead due to the additional malloc.

For dicts with 6 or more entries, the ma_smalltable member is wasted
space, but then these are large(r) dicts so 8 slots more or less doesn't
make much difference.  They still benefit all the time from removing
ubiquitous dynamic null-pointer checks, and get a small benefit (but
relatively smaller the larger the dict) from not having to do two
mallocs, two frees, and a resize on the way *to* getting their sixth
entry.

All in all it appears a small but definite general win, with larger
benefits in specific cases.  It's especially nice that it allowed to
get rid of several branches, gotos and labels, and overall made the
code smaller.
2001-05-22 20:40:22 +00:00
..
.cvsignore Ignore a bunch of generated files. 2000-05-02 18:34:30 +00:00
abstract.c Reimplement PySequence_Contains() and instance_contains(), so they work 2001-05-05 21:05:01 +00:00
bufferobject.c REMOVED all CWI, CNRI and BeOpen copyright markings. 2000-09-01 23:29:29 +00:00
cellobject.c Variety of small INC/DECREF patches that fix reported memory leaks 2001-03-13 01:58:22 +00:00
classobject.c init_name_op(): add (void) to the argument list to make it a valid 2001-05-22 02:33:08 +00:00
cobject.c REMOVED all CWI, CNRI and BeOpen copyright markings. 2000-09-01 23:29:29 +00:00
complexobject.c SF bug [ #409448 ] Complex division is braindead 2001-03-18 08:21:57 +00:00
dictobject.c SF patch #425242: Patch which "inlines" small dictionaries. 2001-05-22 20:40:22 +00:00
fileobject.c file_getiter(): make iter(file) be equivalent to file.xreadlines(). 2001-05-22 16:48:37 +00:00
floatobject.c SF bug #422177: Results from .pyc differs from .py 2001-05-08 15:19:57 +00:00
frameobject.c SF patch 419176 from MvL; fixed bug 418977 2001-05-08 04:08:59 +00:00
funcobject.c Since Py_TPFLAGS_HAVE_WEAKREFS is set in Py_TPFLAGS_DEFAULT, it does not 2001-05-03 16:04:13 +00:00
intobject.c Use Py_CHARMASK for ctype macros. Fixes bug #232787. 2001-03-06 12:12:02 +00:00
iterobject.c Discard a misleading comment about iter_iternext(). 2001-05-01 17:01:25 +00:00
listobject.c Fix core dump whenever PyList_Reverse() was called. 2001-02-12 22:06:02 +00:00
longobject.c Rich comparisons fall-out: 2001-01-17 15:33:18 +00:00
methodobject.c REMOVED all CWI, CNRI and BeOpen copyright markings. 2000-09-01 23:29:29 +00:00
moduleobject.c Repair "module has no attribute xxx" error msg; bug introduced when 2001-05-12 20:24:22 +00:00
object.c Cosmetic: code under "else" clause was missing indent. 2001-05-11 03:36:45 +00:00
obmalloc.c Identifiers matching _[A-Z_]\w* are reserved for C implementations. 2001-03-11 18:36:13 +00:00
rangeobject.c SF patch #103158 by Greg Ball: Don't do unsafe arithmetic in xrange 2001-01-15 18:58:56 +00:00
sliceobject.c SF patch #408326 by Robin Thomas: slice objects comparable, not 2001-03-20 12:41:34 +00:00
stringobject.c This patch changes the way the string .encode() method works slightly 2001-05-15 12:00:02 +00:00
tupleobject.c Speed tuple comparisons in two ways: 2001-05-15 20:12:59 +00:00
typeobject.c REMOVED all CWI, CNRI and BeOpen copyright markings. 2000-09-01 23:29:29 +00:00
unicodectype.c unicode database compression, step 3: 2000-09-25 21:48:13 +00:00
unicodeobject.c This patch changes the behaviour of the UTF-16 codec family. Only the 2001-05-21 20:30:15 +00:00
unicodetype_db.h forgot to check in the new makeunicodedata.py script 2001-01-21 17:01:31 +00:00
xxobject.c REMOVED all CWI, CNRI and BeOpen copyright markings. 2000-09-01 23:29:29 +00:00