Mailing List Archive

db_send_message_lines change
Hi All,

Last Friday, while walking through db_send_message_lines looking for
stuff
that made it slow, I found something interesting:

To fill the buffer, every character from the messageblock is appended
to the
buffer: sprintf(buffer, "%s%c", buffer, *nextpos)
This operation can be really slow, especially when the string in the
buffer
is really long. The position to put the character *nextpos in, has to
be found
by finding the length of the string in buffer.

I've changed this appending of characters to:
buffer[buffer_pos++] = *nextpos

buffer_pos is used to "remember" the length of the string in the
buffer. Of
course, buffer_pos is initially 0, and is reset to 0 every time the
buffer
is cleared.

Earlier today I've put this code in CVS for the 2.0 branch

Ilja

--
IC&S
Koningsweg 4
3582 GE UTRECHT
Re: db_send_message_lines change [ In reply to ]
I've now also made this change in the 1.x branch

Ilja

On Monday, Oct 13, 2003, at 12:28 Europe/Amsterdam, Ilja Booij wrote:

> Hi All,
>
> Last Friday, while walking through db_send_message_lines looking for
> stuff
> that made it slow, I found something interesting:
>
> To fill the buffer, every character from the messageblock is appended
> to the
> buffer: sprintf(buffer, "%s%c", buffer, *nextpos)
> This operation can be really slow, especially when the string in the
> buffer
> is really long. The position to put the character *nextpos in, has to
> be found
> by finding the length of the string in buffer.
>
> I've changed this appending of characters to:
> buffer[buffer_pos++] = *nextpos
>
> buffer_pos is used to "remember" the length of the string in the
> buffer. Of
> course, buffer_pos is initially 0, and is reset to 0 every time the
> buffer
> is cleared.
>
> Earlier today I've put this code in CVS for the 2.0 branch
>
> Ilja
>
> --
> IC&S
> Koningsweg 4
> 3582 GE UTRECHT
>
> _______________________________________________
> Dbmail-dev mailing list
> Dbmail-dev@dbmail.org
> http://twister.fastxs.net/mailman/listinfo/dbmail-dev
Re: db_send_message_lines change [ In reply to ]
On Mon, 2003-10-13 at 06:28, Ilja Booij wrote:
> I've changed this appending of characters to:
> buffer[buffer_pos++] = *nextpos

Any benchmark on this? Even a really rough one? Just curious.
Re: db_send_message_lines change [ In reply to ]
Well, I have not performed a real dbmail benchmark, only
a simple one. This benchmark consisted of a simple
function that fills a buffer of length 4096 30 times

What I found is that for this buffer length, the old
code (using sprintf()) is about 20 times slower. Using
a profiler I found that a lot of time (about 75%) is
spent in strlen(). Every time a character is appended,
the end of the string in the buffer needs to be found,
so strlen() is used.

I do not know if there is a really big speed-up when doing
pop over the network, but this change should be able
to save some cpu cycles.

Ilja

On Monday, Oct 13, 2003, at 14:58 Europe/Amsterdam, Matthew T. O'Connor
wrote:

> On Mon, 2003-10-13 at 06:28, Ilja Booij wrote:
>> I've changed this appending of characters to:
>> buffer[buffer_pos++] = *nextpos
>
> Any benchmark on this? Even a really rough one? Just curious.
>
> _______________________________________________
> Dbmail-dev mailing list
> Dbmail-dev@dbmail.org
> http://twister.fastxs.net/mailman/listinfo/dbmail-dev