We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil – Donald Knuth
My Treasure Book generator has serious speed issues. It’s slower than frozen molasses. PHP isn’t my language of choice and my experience is limited. When I wrote the generator, I made quick and dirty decisions. Mostly I just wanted a proof of concept to demonstrate the functionality of the idea. Now, I need to address the fact that it’s slow.
The first issue I tackled was single-returns per hoard type. Shifting it over to array value returns resulted in next to nothing. It had worked previously for the Modern Name Generator. The difference is that the name generator was IO bound. The treasure book is not. Most of the calls are pretty lightweight and quick. Something was sucking up serious resources and my ad-hoc approach to fixing the application wasn’t producing results.
I really needed to figure out what the issue was. Like many programmers, I was quick to jump on prior knowledge without looking. When that failed, I was forced to find out how to profile php code. Turns out its not that hard. Enter Xdebug and KCacheGrind ( For the Windows folks, WinCacheGrind is the equivalent to KCacheGrind.). The former is a quick install and the latter is packaged with KDE. Tweak php.ini as described and you can profile php easily.
My code isn’t really the issue. How I used TCPDF is the heart of the problem. If I’d bothered to RTFM, I’d have known I was doing it wrong. As the Performances (sic) page states,
Avoid using the HTML syntax (writeHTML and writeHTMLCell methods) if not strictly required;
It isn’t. It was convenient at the time. Now I have to rework to do a new layout.