Big performance hit in XmlDocument::getDocumentElement


#1

I recently got a bug report about loading a project with a certain plugin freezing my application.

The issue is that the plugin is generating a 5Mb+ chunk, and Juce takes a seriously long time to load this project.

 

I'm using XML as my application project file type, the saved data is like this:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE CARLA-PROJECT>
<CARLA-PROJECT VERSION='2.0'>
<Plugin>
  <Data>
   <ChunkData>
<!-- big chunk here -->
   </ChunkData>
  </Data>
 </Plugin>
</CARLA-PROJECT>

 

With some debugging I see that Juce spends a lot of time doing String operations.

Is it possible to optimize this?

 

EDIT: The "freeze" happens during this line:

ScopedPointer<XmlElement> xmlElement(xmlDoc.getDocumentElement(true));

#2

Well, if there's a massive chunk of string data, obviously a lot of string operations will be needed to parse it..

If you profile what's happening, and can suggest some optimisations that would help in your particular case, then I'd be glad to consider them!


#3

Well, if there's a massive chunk of string data, obviously a lot of string operations will be needed to parse it..

What I'm seeing is lots of allocation, copying and appending of text.

If everything is contained in a single block, like this:

<Chunk>

SGVsbG8gV29ybGQK....

</Chunk>

Shouldn't juce just load the entire thing?

 

In any case, I'll look at what the code is doing and try to see if I can optimize it.

If not I can always try compressing the chunk data.

 


#4

Sure, I understand, but it's impossible to optimise stuff like this without using a proper profiler and seeing the stack traces that are the hotspots. If you can point to any particular areas and suggest improvements, great!


#5

Alright, I was able to fix this by switching a String class with a MemoryOutputStream one, then converting it to a string when all the data appending is complete.

btw, I used a print to calculate the chunk, it was using 3059640 characters!

 

Here's the patch:

https://github.com/falkTX/Carla/commit/c68cbfde8a27f8ec3d5306c5262d23573423d8e4.patch


#6

Ah, perfect - I had my fingers crossed that it'd be something simple like that! Thanks - I'll push something along those lines asap!