Ethereal-dev: Re: [Ethereal-dev] compare_proto_id taking up 20% of Ethereal's time

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Richard Sharpe <rsharpe@xxxxxxxxxxxxxxxxx>
Date: Sun, 16 Nov 2003 16:09:10 -0800 (PST)
On Sun, 16 Nov 2003, Guy Harris wrote:

> On Sun, Nov 16, 2003 at 10:04:32AM -0800, Richard Sharpe wrote:
> > Yes, then the big problem is that we need to run an AWK script across all 
> > the source changing all those protocol index def'ns.
> 
> No - we continue to have "proto_register_protocol()" return an index
> (which is what "proto_tree_add_item()" and
> "proto_tree_add_protocol_format()" expect); we just change what's inside
> a dissector handle, and have "dissector_add()" and the like do the
> translation.

OK, I must be thick, because I am not understanding ...

The performance problem, at least according to gprof data seems to be that 
compare_proto_id is called far too many time. It is called because 
find_protocol_by_id is walking the list of protocols and passing 
compare_proto_id as the equality function:

list_entry = g_list_find_custom(protocols, &proto_id, compare_proto_id);

Now, a large number of functions in proto.c do this:

proto_get_protocol_<attr>(int proto_id)
{
        protocol_t *protocol;
                                                                                
        protocol = find_protocol_by_id(proto_id);
        return protocol-><attr>;
}

and proto_get_protocol_short_name is the biggest user of 
find_protocol_by_id in my gprof trace, followed by 
proto_is_protocol_enabled.

It seems to me that we cannot simply change a proto_id into a pointer but 
cast it to an int, as that will cause problems on 64-bit platforms.

So, I want to change all those routines that currently deal with a 
proto_id to deal with a protocol_t * ...

But that requires changes to lots of places, including all dissectors 
(although the changes will be minor in each of them).
 
Regards
-----
Richard Sharpe, rsharpe[at]ns.aus.com, rsharpe[at]samba.org, 
sharpe[at]ethereal.com, http://www.richardsharpe.com