Speed up clear()
authorsprout <sprout@Pint.local>
Sat, 30 Jan 2010 06:17:30 +0000 (22:17 -0800)
committersprout <sprout@Pint.local>
Sat, 30 Jan 2010 06:17:30 +0000 (22:17 -0800)
commitd8f1fa9844cbf2e1beddbe01297de1235d7a7622
treeca4d78604ca7d76557b8a579eef7027949cbf8ce
parent5a7551626dffba6d13e64059529675ab944372cf
Speed up clear()

Before the clear() bug was fixed, t/03_bighash.t took 45 sec., for me
at least. It was using a ‘first_key next_key*’ approach, which ended
up skipping keys, since they were being deleted during iteration. When
clear() was fixed, a ‘first_key+’ approach was used, which was *much*
slower, since it created a new iterator object for each key. That test
script ended up taking 2 hours!

I found that a compromise, using ‘first_key next_key*’ repeatedly
until first_key stopped returning a key, would reduce the time to 65
seconds. Then I found that pushing the functionality further inside
the engine and freeing the index or bucket list reduces it to 25 sec-
onds. Transactions make things a little more complicated, so I fall
back to the compromise in the presence of transactions.
lib/DBM/Deep.pm
lib/DBM/Deep/Engine.pm
lib/DBM/Deep/Engine/Sector/Reference.pm
lib/DBM/Deep/Hash.pm