Hi Jorge, On Thu, May 22, 2008 at 05:23:04PM -0400, Jorge Arellano Cid wrote:
Hi Johannes,
On Thu, May 22, 2008 at 12:21:51PM +0200, Johannes Hofmann wrote:
Hi,
to see which part of dillo consumes which amount of memory, I hacked together a version of dlib.c that counts memory that was allocated via dMalloc(). A malloc_tag allows to assign the mallocs to specific parts in the code. In the patch below I use malloc_tag = 1 for cache stuff, malloc_tag = 2 for text strings that are passed dw2 and malloc_tag = 0 for everything else. It's fun to see how memory get's allocated and free'd while loading. Here is the output once the huge mysql manual page is loaded:
====> malloc size 5185114 26967623 6602392 0
So that's 6M for text strings, 26M cache and 5M other. Of course there is also all the dw2 stuff that is not taken into account here.
Yes, and dw2 stuff should be the main part...
Yes, it probabely is, but I wanted to understand what parts use how much memory. One thing I've seen is that Local_Buf in html.cc keeps a copy of the page until it's deleted. Do you think we can free Local_Buf in closeParser() already? It works fine in my test. Another thing is the way new incoming html is handled in DilloHtml::write(). It' get's decoded in a new string and is then copied to the end of Local_Buf. Maybe we could avoid the copy by letting the decoder write it to the right place? Other than that the memory usage (dlib based) seems reasonable to me.
BTW, textblock delete's the text strings that are allocated using malloc(). That's not allowed and might cause unexpected behaviour on some platforms.
This is clearly a bug.
A long time ago I thought of dw2 using dlib. Now dw2 is mainly using its own resources. The simple solution would be to let addText to allocate and delete the string. Another way is to study whether is worth to convert dw2 to dlib.
The easiest would be to use just use free() in the Textblock destructor but it would be cleaner to free the space where it was allocated.
It'd be great if we can have gprof profiling working on dillo again. Then use it to see what is the real impact of some optimizations.
A long long time ago (in dillo1), I used to heavily optimize functions to avoid extra strdups. It ended making the code a lot more complex and without any noticeable gain. After that we switched to the simple paradigm of having each function free what it allocated.
Yes, that's true. Some time ago I noticed the huge amount of malloc() and free() that happen while loading a page and I wrote an allocator that get's a large chunk via malloc and then hands out pieces for use in addText(). In the end all text could be free()'d with one call to free. But there was not much of a gain! The standard malloc routines seem to be quite optimized these days :-)
Can you give a hand at enabling profiling again?
I have it working for some time again. My problem was just DragonFly specific and I now have a workaround. Apart from that I compile dw2 and dillo2 with --enable-gprof and fltk2 with --disable-xft. Finally I manually link dillo with the -static and -pg options and the -lXau -lXdmcp libraries added. At http://www.ecademix.com/JohannesHofmann/tmp/refman.prof is a grof output of current dillo loading the 13M mysql page. Cheers, Johannes