[merge] faster knit extraction & better errors if unable to get delta parent

John Arbash Meinel john at arbash-meinel.com
Tue Oct 23 23:10:57 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
>>> +                    try:
>>> +                        next = parents[0]
>>> +                    except IndexError:
>>> +                        raise KnitCorrupt(
>>> +                            self,
>>> +                            "\nversion %s\n"
>>> +                            "    has compression method %r " \
>>> +                            "but index parents %r " % (
>>> +                            cursor, method, parents))
>>> +                    next = parents[0]
>> However this isn't - for two reasons.
>> The first is that it was triggering before because get_parents was
>> reducing the parents by removing absent keys, and
>> get_parents_with_ghosts won't do that, so you will need a index with no
>> parents at all to trigger this for that record.
>> Secondly, there is a cost for exception contexts, and this is right in
>> an inner loop, so I would actually expect this to cost performance
>> as-is.
> 
> Although this will no longer trip for the particular problem we had
> now, it seemed still worth leaving it in to guard against other(?)
> situations where we might have a delta with no parents present.  In
> packs it's probably hard to get a line delta indicated without having
> any parents, so the time cost is not worth it.
> 

BB:tweak

These are the numbers I got:

TIMEIT -s "x = ['parent-1', 'parent-2']" \
  "x[0]"
10000000 loops, best of 3: 0.177 usec per loop

TIMEIT -s "x = ['parent-1', 'parent-2']" \
"try:
  x[0]
except IndexError:
  pass
"
1000000 loops, best of 3: 0.258 usec per loop

TIMEIT -s "x = ['parent-1', 'parent-2']" \
"try:
  x[2]
except IndexError:
  pass
"
100000 loops, best of 3: 3.05 usec per loop

TIMEIT -s 'x = ["parent-1", "parent-2"]' \
'if len(x) > 2: x[2]'
1000000 loops, best of 3: 0.394 usec per loop

Which says that creating a try/except costs 45% of the time of an index lookup.
The last two are just for my curiosity. It seems that actually raising an
exception and catching it costs about 10x more than doing the check manually.
But checking costs about 2x of not checking.

Anyway, I'll go with Robert. That this is core code and the chance of actually
running into this again is low enough to not have extra error handling.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHHnFwJdeBCYSNAAMRAlhHAKCy83zqNtQH1PCSZ0BUsEX8ElWhrwCfUlsN
SJK3lVBG0gL57JuXpm4rRwg=
=W7vm
-----END PGP SIGNATURE-----



More information about the bazaar mailing list