Re: Introduction

From: Serassio Guido <guido.serassio@dont-contact.us>
Date: Fri, 29 Apr 2005 11:16:23 +0200

Hi Evgeny,

At 09.52 29/04/2005, Evgeny Kotsuba wrote:
>>FD_READ_METHOD/FD_WRITE_METHOD macros should be more efficient.
>>Look here:
>>http://cvs.sourceforge.net/viewcvs.py/squid/squid/src/fd.c?rev=1.7.16.9&only_with_tag=nt-2_5&view=auto
>I don't understand why macros may be more efficient.
>I use things like
>int squid_fde::read(char *buf, int len)
>{ int rc=-1;
> switch(type)
> { case FD_SOCKET:
> if(fh < 0)
> { debug(91, 0) ("squid_fde::read WARNING: fh=%i\n",fh);
> rc = -1;
> break;
> }
> rc = recv(fh, buf, len, 0 /* MSG_DONTWAIT ? */);
> break;
> case FD_NONE:
> fatalf("Attempt to Read with FD_NONE type handle %i bytes",
> len);
> return -1;
> case FD_PIPE:
> case FD_PIPE_READ:
> rc = ::read(fh, buf, len);
> break;
> default:
> rc = ::read(fh, buf, len);
> }
> if(rc>0) bytes_read += rc;
> return rc;
>}

Your code is more bigger and long, for any I/O you do:

- a function call with stack and context switch (your function seems to be
not inlined)
- a fd_table lookup
- a decision
- call to the correct I/O function.

Macros are defined in squid.h as:

#define FD_READ_METHOD(fd, buf, len) (*fd_table[fd].read_method)(fd, buf, len)
#define FD_WRITE_METHOD(fd, buf, len) (*fd_table[fd].write_method)(fd, buf,
len)

read_method and write_method pointers are initialized during fd_open

Everywher in the 2.5 and 3.0 source code you find already only
the FD_READ_METHOD/FD_WRITE_METHOD macros instead of read() and write().

Whith macros for any I/O we do:
- a fd_table lookup for the function pointer
- call to the correct I/O function with the previous pointer

More faster.

Regards

Guido

-
========================================================
Guido Serassio
Acme Consulting S.r.l. - Microsoft Certified Partner
Via Lucia Savarino, 1 10098 - Rivoli (TO) - ITALY
Tel. : +39.011.9530135 Fax. : +39.011.9781115
Email: guido.serassio@acmeconsulting.it
WWW: http://www.acmeconsulting.it/
Received on Fri Apr 29 2005 - 03:16:44 MDT

This archive was generated by hypermail pre-2.1.9 : Sun May 01 2005 - 12:00:06 MDT