As a relative newcomer, I'm just starting to get into Drupal code. I'm no PHP stud and not not savvy with MySQL nuances either. I'd like to use this avatar_selection module as an ongoing opportunity to try to improve performance for selecting and rendering the image list in the Manage page.
I just took a look at the code and here are some general thoughts.
- I see that you're doing some processing on each image as it's rendered. It might be best to do that sort of processing in a separate loop, or perhaps offer a checkbox to allow the user to decide whether the extra processing will be done during their session.
- When generating $avatars_list, the foreach loop copies the entire array, in memory and into the new $avatars_indexed array. There has to be a ton of overhead there with the 7500 images I'm sending into there (total memory footprint = 22500 images consuming about 22MB of RAM every time a page is rendered!). I tried changing $image to &$image but there wasn't any obvious effect.
- Note that the foreach statement seems to have the arguments backwards:
foreach ($avatars as $image => $name) should be
foreach ($avatars as $name => $image) no ? (PHP doc on foreach)
- I also changed the foreach to a for-loop with no perceived improvement.
- There are two indexes on the avatar_selection table, PRIMARY, and 'avatar'. Since one is redundant I removed PRIMARY. Any objection?
- We are planning to use OG and I appreciate the code in there, but we're not using weights and not assigning a unique name to avatars, so as a test I changed the selection to Order By avatar (which is indexed where 'weight' and 'name' are not), and I commented out anything related to those fields and replaced them with 'avatar'. There was no noticable improvement in performance.
Remember that these are just local experiments, not change proposals. Considering all of the apps in the world that operate on images I'm sure there is a way to optimize the selection of large sets of images and rendering of subsets one page at a time.
Comments welcome here about anything related to performance. Sound like a plan?
Comments
Comment #1
stella CreditAttribution: stella commentedTaking each of your points individually:
Cheers,
Stella
Comment #2
stella CreditAttribution: stella commentedTry the latest dev release (available later today). I've changed the function which fetches the list of avatars. It may help.
Cheers,
Stella
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #4
Starbuck CreditAttribution: Starbuck commentedRe-opening: Tried latest Dev cut from Aug 05. I see the avatar_selection table itself is updated with all image files, but table avatar_selection_roles does not exist so invoking the code after update results in errors. Please advise.
Thanks for your efforts.
Comment #5
stella CreditAttribution: stella commentedPlease run update.php, which you should be doing every time you upgrade any module.
Comment #6
Starbuck CreditAttribution: Starbuck commentedI disabled, updated, re-enabled, updated, but I didn't do a disable/uninstall before updating the module, so hook_install wasn't run. I'll take another shot at this tomorrow.
It looks like all files get deleted from the directory during uninstall. My image directory is a soft link to a path shared by my forum, so deleting all of the images isn't desirable, and the folder isn't going to be deleted. I guess I'll need to make a site-specific mod to avoid that part of the code - agreed?
Thanks again.
Comment #7
stella CreditAttribution: stella commentedYou shouldn't need to uninstall the module in order to get the new tables. If update.php is not adding the two new tables (avatar_selection_roles and avatar_selection_og), then tell me the schema_version number from the system table for the avatar selection module. If it is set to 6002, you may need to grab the latest dev release from today.
Cheers,
Stella
Comment #8
Starbuck CreditAttribution: Starbuck commentedYes, it is 6002. I'm just getting familiar with Drupal internals but I wouldn't expect hook_install to execute on an update. Whatever the case, I will wait another day just in case the dev code is in a precarious state and then load the latest build. If there are issues with this specific installation, I don't want to bother you with them. I will get the latest dev fully installed and we'll work forward from there, focusing on the module.
Regards and thanks as always.
Comment #9
stella CreditAttribution: stella commentedhook_install isn't run on an update, but there is a hook_update_N function (
avatar_selection_update_6003()
) which should be run when you run update.php in the latest dev release. Please let me know if the latest dev release fixes the issue for you.Comment #10
stella CreditAttribution: stella commentedReleased in Avatar Selection 6.x-1.5 and 5.x-2.7.
Cheers,
Stella
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.