GNOME Bugzilla – Bug 433782
Optimise vCard folding
Last modified: 2007-06-05 02:42:55 UTC
Please describe the problem: It takes a very long time to add a large picture to a contact. The processor time is mostly spent on folding lines in e-vcard.c. I've optimised the folding and created a patch. Please someone have a look at it, especially with regard to utf-8 correctness. The speedup on my system is in the range 10x-100x. This problem is closely related to bug #312581, but is most easily tracked as separate bugs. Steps to reproduce: Actual results: Expected results: Does this happen every time? Other information:
Created attachment 87117 [details] [review] Suggested algorithm (applies to 1.10.1) Note that this algorithm folds the first line after 75 characters and the following lines at 73. This is probably not correct according to RFC-822. The current implementation works the same way, so it should be safe to continue doing that.
Ross, you have any thoughts on this?
Oh, nice patch. It could be made even faster by manually looping over the string with g_utf8_next_char, because it will count 76 unicode characters twice per loop (once when calculating the length, and then again when getting the pointer).
Created attachment 87366 [details] [review] Same patch with single iteration through string Like this? The code is a bit more unreadble, but should in theory be a bit quicker. Choose whichever you like better..
I did a patch in bug #336574 in same part of code as this patch, but with other approach.
There are 3 suggested patches now. I believe all of them work. For me the most important is that one of them is chosen and applied. I think Milan's patch is the quickest (but also the least maintainable code, probably). Ross, could you give thumbs up for one of them, or request further work if you have any suggestions for improvement?
Great. I would prefer to push Milan's patch for 2.11.2 unless Ross has some more improvements that can be done along with this :)
Milan's patch looks good to me. Preserving the exact output isn't really a great concern, and removing the variable line length might clean the code up a little.
Created attachment 87923 [details] [review] String buffer preallocated, line width=75 characters Here's another go at the folding then. This time it's a simplified version of Milan's patch. It makes all lines 75 characters wide. On my laptop, add_contact with 15 fields and a 250k photo takes roughly: 37s with current code 3s with my first patch 0,4s with Milan's patch 0,15s with this patch Numbers for get_contact are more or less proportional.
Created attachment 87931 [details] [review] String buffer preallocated, line width=75 characters, try again
Cool guys. Great patch. I will push the last one for 2.11.2. Ross: Does bug #312581 still hold good? or should we extend this work to that?
I think this patch should be committed, and then I'll re-sync the relevant changes in #312581 against latest svn.
*** Bug 336574 has been marked as a duplicate of this bug. ***
Please Commit this for head
I commited this to trunk.
*** Bug 442331 has been marked as a duplicate of this bug. ***