INADA Naoki added the comment:

Digging history, duplicated code is introduced here. (1997-01-17)

https://github.com/python/cpython/commit/99304174680d4c724476dad300ae7fc638842bf0#diff-2131209d0deb0e50c93a88ec6c7b0d52

        /* Optimizations based on observations by Jyrki Alakuijala
           (paraphrased):
           - This routine is very heavily used, so should be AFAP
           (As Fast As Possible).
           - Most of the time, the first try is a hit or a definite
           miss; so postpone the calculation of incr until we know the
           first try was a miss.
           - Write the loop twice, so we can move the test for
           freeslot==NULL out of the loop.
           - Write the loop using pointer increments and comparisons
           rather than using an integer loop index.
           Note that it behooves the compiler to calculate the values
           of incr*sizeof(*ep) outside the loops and use this in the
           increment of ep.  I've reduced the number of register
           variables to the two most obvious candidates.

At the time, there was a single lookdict function, and three tries.

* The comment said the first try was for skipping `inc` calculation.
  While `inc` had been removed already, I think this implies skipping
  freeslot==NULL test.

* After first try, there are two loop for skipping freeslot==NULL test
  until first dummy found.  This optimization looks gone.


As I said above, lookdict_unicode_nodummy and lookdict_split only search
from table without dummies.
And lookdict_unicode() and lookdict() are not so important lookmapping() was in 
1997,
duplicated code only for skipping one freeslot==NULL doesn't make sense.

One possible optimization is removing freeslot completely. because:

* freeslot is used only when inserting. finding is more important.
* insertdict() can find dummy quickly, only looking dk_indices.

But before trying optimization, I suggest to remove duplicated code first.
Macro bench doesn't show significant difference at least.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29304>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to