Well, I spent about 8 hours rewriting the WURFL XML parsing/loading scripts hoping for a major speed increase by using XMLReader instead of SimpleXML.
Specifically, I have rewritten TeraWurflLoader.php and created the abstract class TeraWurflXMLParser as well as two more classes: TeraWurflXMLParser_XMLReader and TeraWurflXMLParser_SimpleXML.
End result: SimpleXML was faster than XMLReader to begin with, and appears to use less memory!
I was able to remove a bunch of old code that was unused and confusing from the 1.x versions and separated much of the logic in the XML parser, optimizing it along the way. It now parses about 15% faster on my machine, loading the WURFL with no cached data in 9.8 seconds on my laptop, which is quite a bit faster than before.
- Code: Select all
Database Update OK
Total Time: 9.795273065567
Parse Time: 1.8240180015564 (TeraWurflXMLParser_SimpleXML)
Validate Time: 0.0045268535614014
Sort Time: 1.9420890808105
Patch Time: 0.16571807861328
Database Time: 5.5644080638885
Cache Rebuild Time: 0.29451298713684
Number of Queries: 304
PHP Memory Usage: 14.19 MB
--------------------------------
WURFL Version: www.wurflpro.com - 2010-02-03 10:31:00 (Wed Feb 03 10:35:26 -0600 2010)
WURFL Devices: 12883
PATCH New Devices: 38
PATCH Merged Devices: 2
The XML Parser that is used to process the wurfl.xml file (and patch files) is determined by TeraWurflXMLParser::getInstance() as follows:
- Code: Select all
final public static function getInstance(){
if(function_exists('simplexml_load_file')){
require_once "TeraWurflXMLParser_SimpleXML.php";
return new TeraWurflXMLParser_SimpleXML();
}elseif(class_exists('XMLReader')){
require_once "TeraWurflXMLParser_XMLReader.php";
return new TeraWurflXMLParser_XMLReader();
}else{
throw new Exception("No suitable XML Parser was found. Please enable XMLReader or SimpleXML");
}
}