6.0.0-alpha14
6/25/25

[#8627] Improve String::wordwrap() performance
Summary Improve String::wordwrap() performance
Queue Horde Framework Packages
Queue Version FRAMEWORK_3
Type Enhancement
State Resolved
Priority 1. Low
Owners
Requester ryu (at) ryux (dot) org
Created 10/07/2009 (5740 days ago)
Due
Updated 09/29/2011 (5018 days ago)
Assigned
Resolved 09/29/2011 (5018 days ago)
Milestone
Patch No

History
09/29/2011 09:18:10 PM Jan Schneider Comment #9
State ⇒ Resolved
Reply to this comment
See also ticket #9405.
09/29/2011 09:17:45 PM Git Commit Comment #8 Reply to this comment
Changes have been made in Git for this ticket:

Prefer mb_substr() over iconv_substr() because it's several magnitudes 
faster (Evert Pot, Request #8627).

  2 files changed, 12 insertions(+), 12 deletions(-)
http://git.horde.org/horde-git/-/commit/839b9907b6ccadc4935eaf9b88a1d4c609074863
09/29/2011 09:12:19 PM Jan Schneider Comment #7 Reply to this comment
Thanks for the analysis. Btw, encoded photo attributes should not be 
run through wordwrap anymore after commit 
d90a36975cb9417554c78d991b170f795ac21712.
09/29/2011 02:40:15 PM evert (at) rooftopsolutions (dot) nl Comment #6 Reply to this comment
I isolated this problem down to the user of iconv_substr. It's 
incredibly slow compared to mb_substr, and it gets called *a lot*.

Here's a benchmark script:
http://pastebin.com/r63kUt22

On my mac, the difference is very much visible, but not terrible performance:

iconv_substr: 0.014400005340576
mb_substr: 0.00049901008605957
substr: 3.7193298339844E-5

On 2 linux machines we tried, the numbers looked more like this:

iconv_substr: 8.3735179901123
mb_substr: 0.00039505958557129
substr: 4.8160552978516E-5

Yes that's 8 seconds for iconv_substr,  0.0004 seconds for mbstring 
and 0.00005 for the non-unicode aware function.

So my fix is to change Horde_String::substr and prefer mbstring over iconv
10/07/2009 08:55:04 AM ryu (at) ryux (dot) org Comment #5 Reply to this comment
Ok, I try to do something to improve this ! But, maybe, it will be long :)

[Show Quoted Text - 16 lines]
10/07/2009 08:45:32 AM Jan Schneider Comment #4 Reply to this comment
I can work on this problem if you want. But I need more specifications...
Do you have a list of rules and others considerations ? Maybe a RFC ?
If it was only one, it would be simple:

http://tools.ietf.org/html/rfc2445

http://tools.ietf.org/html/rfc2426

http://www.imc.org/pdi/vcal-10.txt

http://www.imc.org/pdi/vcard-21.txt
Is exists unit tests for this method ?
Yes, in the Utils framework package.
And for the size message problem ? What is the solution ?
To implement partial messages in SyncML. Request #6658 might help too.
10/07/2009 08:26:35 AM ryu (at) ryux (dot) org Comment #3 Reply to this comment
I can work on this problem if you want. But I need more specifications...

Do you have a list of rules and others considerations ? Maybe a RFC ?

Is exists unit tests for this method ?



And for the size message problem ? What is the solution ?



Thanks
10/07/2009 07:52:52 AM Jan Schneider Summary ⇒ Improve String::wordwrap() performance
 
10/07/2009 07:52:24 AM Jan Schneider Queue ⇒ Horde Framework Packages
Version ⇒ FRAMEWORK_3
 
10/07/2009 07:51:42 AM Jan Schneider Type ⇒ Enhancement
State ⇒ Accepted
Priority ⇒ 1. Low
 
10/07/2009 07:51:22 AM Jan Schneider Comment #2 Reply to this comment
Improving this won't help with synchronization, because the image 
still wouldn't fit into a single SyncML message.

String::wordwrap() being slow is a known issue though. This is 
happening because of the special line folding rules and charset 
considerations that are required when wordwrapping vCard/iCalendar 
data. Some small improvements have already been in CVS, but this 
method probably has to be re-written from scratch.
10/07/2009 07:16:06 AM ryu (at) ryux (dot) org Comment #1
Patch ⇒ No
State ⇒ Unconfirmed
Milestone ⇒
Queue ⇒ Turba
Summary ⇒ Turba export doesn't work with (big) image
Type ⇒ Bug
Priority ⇒ 2. Medium
Reply to this comment
Turba export is very very long when a photo is added to contact (132 
Ko for example) and it finish by :



Oct 07 08:51:18 HORDE [debug] [horde] Sending replace from server: 
20091007082330.381433t87qr4a12a@mail.example.com [pid 18652 on line 
577 of "/data/internet/mail.example.com/_www.1.2.4/lib/SyncML/Sync.php"]

Oct 07 08:51:18 HORDE [debug] [horde] Maximum message size 20000 
approached during replace; current size: 497 [pid 18652 on line 586 of 
"/data/internet/mail.example.com/_www.1.2.4/lib/SyncML/Sync.php"]

Oct 07 08:51:18 HORDE [warning] [horde] Data item won't fit into a 
single message. Partial sending not implemented yet. Item will not be 
sent! [pid 18652 on line 590 of 
"/data/internet/mail.example.com/_www.1.2.4/lib/SyncML/Sync.php"]



When we look a bit more, we find that the method String::wordwrap is 
very long (> 15 minutes for me) to explode photo, causing a timeout to 
sync process with a mobile... This function is called in 
iCalendar::_exportvData()



To sum up how to reproduce :



- add a photo with important size (130 ko)

- sync mobile



result : 2 ways

1. timeout (after 10 min) and stop (with slow sync on next sync) (with Edge)

2. no timeout (15 min) but problem on transfer (with WiFi)



I m ready to create a fix this bug, but I need help on what to do...



Thanks

Saved Queries