Re: [xml] Useless function calls in xmlSetProp()?
- From: Julien Charbon <jch 4js com>
- To: veillard redhat com
- Cc: xml gnome org
- Subject: Re: [xml] Useless function calls in xmlSetProp()?
- Date: Fri, 22 Feb 2008 10:06:37 +0100
[Argh! I joined a patch not a prog in my previous email. Sorry. This
time I'm good. Just ignore my previous email]
Daniel Veillard wrote:
On Fri, Feb 08, 2008 at 05:17:31PM +0100, Julien Charbon wrote:
Seems fine and clear. Attached to this email the "final" patch
against current trunk.
okidoc, rereviewed it, it looks fine, applied, tested still fine, so I
commited it, thanks a lot !
Thanks to you, for reviewing and applying patch.
In completely unscientific testings, runtest number of allocs are reduced
from 3,058,476 to 3,053,663 which is around 0.15% , it really depends on
the kind of documents used and what processing.
Right. I made a tiny prog [again], that show time made by a call to
xmlSetProp() with an attribute value that double in size every iteration:
- With old xmlSetProp():
$ ./test-setprop-big
Size: 8 Time: 000:000014397
Size: 16 Time: 000:000003429
Size: 32 Time: 000:000003164
Size: 64 Time: 000:000004435
Size: 128 Time: 000:000033918
Size: 256 Time: 000:000017600
Size: 512 Time: 000:000042089
Size: 1024 Time: 000:000120426
Size: 2048 Time: 000:000400574
Size: 4096 Time: 000:001471683
Size: 8192 Time: 000:005275916
Size: 16384 Time: 000:020225833
Size: 32768 Time: 000:078549300
Size: 65536 Time: 000:304803839
Size: 131072 Time: 001:240064893
Size: 262144 Time: 004:963828528
Size: 524288 Time: 019:846718130
Size: 1048576 Time: 078:606054215
- With "new" [now current] xmlSetProp():
$ ./test-setprop-big
Size: 8 Time: 000:000004981
Size: 16 Time: 000:000001847
Size: 32 Time: 000:000000906
Size: 64 Time: 000:000000926
Size: 128 Time: 000:000001011
Size: 256 Time: 000:000001327
Size: 512 Time: 000:000001842
Size: 1024 Time: 000:000002458
Size: 2048 Time: 000:000004280
Size: 4096 Time: 000:000007559
Size: 8192 Time: 000:000022546
Size: 16384 Time: 000:000028533
Size: 32768 Time: 000:000054189
Size: 65536 Time: 000:000107761
Size: 131072 Time: 000:000218971
Size: 262144 Time: 000:000584088
Size: 524288 Time: 000:001057238
Size: 1048576 Time: 000:002148980
[Yes, attributes with value size of 1 MB are unrealistic, it is just
to show how xmlSetProp() scaled before setprop.patch]
Knowing these results, maybe there is a new possible performance
improvement:
According on a quick run of valgring/callgrind on test-setprop-big,
old bad scaling is due to xmlStringGetNodeList() that call too much
xmlStrLen() through call sequence:
xmlNodeAddContent{Len}() -> xmlStrnCat() -> xmlStrLen().
Thus, I will check if some improvements can be done
on xmlStringGetNodeList() to make it more scalable...
P.S: Joined test-setprop-big.c was compiled with:
$ gcc -Wall test-setprop-big.c -o test-setprop-big $(xml2-config
--cflags --libs) -lrt -g -O2
--
Julien
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <libxml/tree.h>
#include <libxml/xmlstring.h>
#define SIZE (1024*1024)
#define VALUE "value & "
struct timespec diff(struct timespec start, struct timespec end)
{
struct timespec time;
if ((end.tv_nsec-start.tv_nsec)<0) {
time.tv_sec = end.tv_sec-start.tv_sec-1;
time.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
} else {
time.tv_sec = end.tv_sec-start.tv_sec;
time.tv_nsec = end.tv_nsec-start.tv_nsec;
}
return time;
}
int main(int argc, char *argv[]) {
LIBXML_TEST_VERSION;
xmlDocPtr doc = NULL;
xmlNodePtr root_node = NULL;
struct timespec start, end, time;
doc = xmlNewDoc(BAD_CAST "1.0");
root_node = xmlNewNode(NULL, BAD_CAST "root");
xmlDocSetRootElement(doc, root_node);
xmlBufferPtr buffer = xmlBufferCreate();
xmlBufferCat(buffer, (unsigned char*)VALUE);
do {
const xmlChar *value = xmlBufferContent(buffer);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
xmlSetProp(root_node, (unsigned char*)"attr", value);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
time = diff(start,end);
printf("Size:\t%d\tTime:\t%03ld:%09ld\n", xmlBufferLength(buffer), time.tv_sec, time.tv_nsec);
xmlChar *tmp = xmlStrdup(value);
xmlBufferCat(buffer, tmp);
xmlFree(tmp);
} while(xmlBufferLength(buffer) <= SIZE);
xmlBufferFree(buffer);
xmlFreeDoc(doc);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]