[CDBI] An optimization question

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Tue Sep 25 19:15:54 BST 2007

Eric Bates wrote;
> When I run it thru the profiler, it appears that most of the top 15
> time consumers are in Class::DBI, but I am a DProf n00b.
> How do I distill all the various Class::DBI calls back to my code?

The only advice I can give on that is to make sure you use dprofpp with the
-r flag, so you can measure real time. IMHO, it's not very useful to measure
CPU time when interacting with a database.

> e.g. somehow 900,000 calls to name_lc seems excessive when the core
> program is handling something on the order of 850 records. But the
> documentation for name_lc basically says "you don't need to know about
> this"; so it's not clear why I'm calling it so frantically.

"Use the Source, Luke." The name_lc() method does exactly what it implies. It
returns the lowercased name of the Column object. That's it. It is used a lot
in object stringification though. You might be able to speed things up ever
so slightly if you avoid object stringification in your code and use $obj->id
instead, but I doubt it'll be worth the effort.

There was a thread with the Subject "Make name_lc go fast" here on the
mailing list back in early April 2007. I'd advise you to dig through the
mailing list archive and read that thread, assuming you haven't already. That
will give you some background on the issue and some ideas for speeding up
name_lc() (notably if your column names are all lowercase already). Although
it could be more efficient, I would expect that you'll probably find that
name_lc() isn't the major bottleneck that you think it is and that the
problem lies elsewhere (probably with your database queries).

Hope this helps,

More information about the ClassDBI mailing list