c - Fastest way to check ancestors using XPath and libxml2 -
i'm working on little reading app processes html documents using libxml2. while processing html tree, check every text() node ancestors choose proper style. headers i'm using following of query see whether node header or not:
boolean(ancestor::*[ self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6]) with 5 mb book, takes 1.1 seconds pass. 2 additional queries emphasis , code styles (with larger set of node names), adds 4.4 seconds.
according apple's instruments, bottleneck line is:
xmlxpathobject *object = xmlxpathnodeeval(node, query, context); i cache context speed things up. there else make faster?
i think xpath expression optimal libxml2. seems don't precompile xpath query. if compile query using xmlxpathcompile once @ beginning of program , evaluate xmlxpathcompiledeval, should see significant speedup.
on top of that, can small speedup removing boolean function query , calling xmlxpathcompiledevaltoboolean directly.
Comments
Post a Comment