Well, I uncovered a real problem with my code today. One that in particular makes the home page (I.E. - the page every single user *must* visit upon logging in, and the page most often visited once you *are* logged in) load like a turtle in a tar pit.
Bad thing #1: in both News and Promotions, a stored procedure gets called to populate a list of headlines to display. In the case of the home page there are three news controls and one promotions control that each make this call. At most, six items get displayed. The stored procedure, however, returns as many headlines as there are that match the query, which can total upwards of 2000 headlines. That's right, the stored procedures bring back nearly 2000 records, of which I toss out all but about 20. That's a whole lot of useless data being shoved down the pipe for no good reason.
But it gets worse.
Bad Thing #2: for each of those records returned, the code actually creates a headline object (thus allocating memory space for every object, not to mention the computation time it takes to create them). That's right -- damn near 2000 objects created, and then all but 20 thrown out.
In my own defense I did not write this code, I inherited it from someone who is long gone. On the other hand, I have owned this code for nearly a year now. I should have spotted this ages ago.
On the upside, this is a relatively easy fix. Serena (my database goddess) will fix the stored procedures to limit the results sets to only what is necessary. Then I'll update my code to prevent this kind of thing from happening again. I suspect by close of business tomorrow we will see a quantum leap in the performance of the site. I just wish I had figured this out a long time ago, it's a real rookie mistake.
Bad developer. No donuts for me.
Bad thing #1: in both News and Promotions, a stored procedure gets called to populate a list of headlines to display. In the case of the home page there are three news controls and one promotions control that each make this call. At most, six items get displayed. The stored procedure, however, returns as many headlines as there are that match the query, which can total upwards of 2000 headlines. That's right, the stored procedures bring back nearly 2000 records, of which I toss out all but about 20. That's a whole lot of useless data being shoved down the pipe for no good reason.
But it gets worse.
Bad Thing #2: for each of those records returned, the code actually creates a headline object (thus allocating memory space for every object, not to mention the computation time it takes to create them). That's right -- damn near 2000 objects created, and then all but 20 thrown out.
In my own defense I did not write this code, I inherited it from someone who is long gone. On the other hand, I have owned this code for nearly a year now. I should have spotted this ages ago.
On the upside, this is a relatively easy fix. Serena (my database goddess) will fix the stored procedures to limit the results sets to only what is necessary. Then I'll update my code to prevent this kind of thing from happening again. I suspect by close of business tomorrow we will see a quantum leap in the performance of the site. I just wish I had figured this out a long time ago, it's a real rookie mistake.
Bad developer. No donuts for me.