Closed (fixed)
Project:
XML sitemap
Version:
6.x-1.x-dev
Component:
xmlsitemap.module
Priority:
Normal
Category:
Task
Issue tags:
Reporter:
Created:
11 Jun 2009 at 04:22 UTC
Updated:
3 Jan 2014 at 00:29 UTC
Jump to comment: Most recent
fwrite() is called 5 times in _xmlsitemap_create_cache_chunk(); in each call, the function is called to output part of a constant string.
Rather than calling 5 times the function, it would be better to call it only once, but passing to it the full string.
Comments
Comment #1
avpadernofwrite()is also called 6 times to output the sitemap data for a single link. Adding 6 times with the previously reported 5 times, plus one call more to output the closing sitemap tag, in a sitemap with just 2 linksfwrite()is called 18 times; for a sitemap with 100 links, the function is called 606 times.Using different code, in a sitemap with 100 links, the function could be called just 102 times. The difference with the actual code is 504 calls less, when the number of links is just 100.
Comment #2
avpadernoIn general, if n is the number of links in a sitemap chunk, the actual code calls
fwrite(n + 1) * 6times, while a different implementation would call the same functionn + 2times. For a sitemap chunk with 1000 links the number of times the function is called would be 6006 times versus 1002.Comment #3
Anonymous (not verified) commentedChanged you mind on the change you did? Check the 5.x code and you'll see that it sets a variable and then calls fwrite(). I'm leaning toward, not worth fixing at this point.
Comment #4
avpadernoSee the code I developed before you rolled it back to beta0; Drupal 5 branch changes were secondary, and it's not said I would promptly update it to the latest developed code for Drupal 6.
Comment #5
dave reidI did some benchmarking on 6.x-2.x to see compare calling fwrite often vs one time per link. The test ran a full drupal bootstrap that just called xmlsitemap_regenerate(). My sitemap was split into two chunks and had only about 6500 links total. The sitemap index and chunks were generated twice for english and french languages. Ran
ab -n 50 http://mysql.drupal6dev.local/test.phpOId code (fwrite called 6 times per link)
Optimized code (1 fwrite per link):
So with a fairly small sitemap, it resulted in about 200ms of an improvement which is a small, but worthwhile step that will become a greater difference as the sitemap grows larger. Thanks Kiam! I have implemented this change in 6.x-2.x with http://drupal.org/cvs?commit=224204.
Comment #6
Anonymous (not verified) commentedComment #7
Anonymous (not verified) commentedComment #8
dave reidCommitted to 6.x-1.x CVS.
http://drupal.org/cvs?commit=259914