[Expat-discuss] Why is expat extremely fast?
david.gregorczyk at googlemail.com
Wed Mar 11 00:26:14 CET 2009
Aleix Conchillo Flaqué schrieb:
> David Gregorczyk wrote:
>> Hey guys,
>> I'm a student from the University of Luebeck in Germany. For my diploma
>> thesis I've just created a small xml parser of ca. 1000 lines of code
>> compared its speed to the expat parser. My results are poor: my parser's
>> speed is only a half of expat's speed. I worked with an endless loop
>> performing switch and if structures. Sometimes a callback function
>> more buffer. Once the loop detects a final flag which is set to 1, it
>> parse the rest of the input stream and exit. The parser works fine
>> but is so
>> lame. What's the reason expat reaches such a great performance?
>> I've tried to understand the source code and failed :-) It's just
>> me. There is so much functionality I do not perform... but my
>> application is
>> still slower.
>> Is there any trick which makes expat so fast?
>> I've searched the internet for an answer, no one could help me. Could
>> Best regards and many thanks for your replies!
> I'm not an Expat expert, but may be your problem is with "...a
> callback function requests more buffer". Does this mean you are
> allocating memory while parsing? If so, that might be your problem.
> Memory allocation is slow.
Thanks for your fast answer. I've found the solution for myself. Because
of the deployment of my application on sensor nodes, memory is once
allocated at the beginning of my algorithm and a custom programmed
memory suite with limited size is used to manage data coming up from a
The memory suite uses a large char array (actually there is UTF-8
support only) and is constructed as a ring buffer. I compute the current
position in that buffer with the modulo operator, the bottleneck of my
algorithm. Modulo needs too much cpu cycles.
To speed up the position computation, I used the compiler optimization
(insigned int)[...] % BUFFER_SIZE_CONSTANT
with BUFFER_SIZE_CONSTANT as a power of 2. Now my code runs faster than
expat, I'm so lucky! :-)
More information about the Expat-discuss