You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Andrew Stitcher <as...@redhat.com> on 2006/12/15 15:39:08 UTC
Small performance issue
One more modest performance speed up (around 1.5%); unfortunately this
is in code generated by the java generator so I don't really know where
to start to fix this:
In the generated file:
BasicDeliverBody.h
The constructor for BasicDeliverBody uses string by value where it
should use it by constant reference,
I'm not sure if there any other implications of this change, but it's
worth doing here, and any other code just initialising string can do it
through a const reference to avoid an unnecessary copy.
[Incidentally I was surprised to see a bare "string" in a header file,
the name space must be polluted somewhere]
Andrew
viz:
> class BasicDeliverBody : virtual public AMQMethodBody
> {
> ...
> BasicDeliverBody(ProtocolVersion version,
> string consumerTag,
> u_int64_t deliveryTag,
> bool redelivered,
> string exchange,
> string routingKey
> ) :
> AMQMethodBody(version),
> consumerTag(consumerTag),
> deliveryTag(deliveryTag),
> redelivered(redelivered),
> exchange(exchange),
> routingKey(routingKey)
> { }
> ...
> }
should be:
class BasicDeliverBody : virtual public AMQMethodBody
{
...
BasicDeliverBody(ProtocolVersion version,
const string& consumerTag,
u_int64_t deliveryTag,
bool redelivered,
const string& exchange,
const string& routingKey
) :
AMQMethodBody(version),
consumerTag(consumerTag),
deliveryTag(deliveryTag),
redelivered(redelivered),
exchange(exchange),
routingKey(routingKey)
{ }
...
}
Re: Small performance issue
Posted by Kim van der Riet <ki...@redhat.com>.
Checked in update. Thanks to Andrew Stiticher for finding the problem,
and to Jim Meyering for helping to fix it.
Kim
On Fri, 2006-12-15 at 19:33 +0100, Jim Meyering wrote:
> Kim van der Riet <ki...@redhat.com> wrote:
> > I'll get to this later this afternoon. Thanks for the patch.
> >
> > There is a function to do this already in CppGenerator: setRef(), which
> > changes both string and FieldTable to const &. A shorter (but
> > equivalent) change would be:
> >
> > - sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") +
> > + sb.append(indent + (defineFlag ? setRef(fieldDomainPair[FIELD_DOMAIN]) + " " : "") +
>
> Yes, that looks better, indeed :-)
> I suppose it's ok to transform "FieldTable" as well as "string".
Re: Small performance issue
Posted by Jim Meyering <ji...@meyering.net>.
Kim van der Riet <ki...@redhat.com> wrote:
> I'll get to this later this afternoon. Thanks for the patch.
>
> There is a function to do this already in CppGenerator: setRef(), which
> changes both string and FieldTable to const &. A shorter (but
> equivalent) change would be:
>
> - sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") +
> + sb.append(indent + (defineFlag ? setRef(fieldDomainPair[FIELD_DOMAIN]) + " " : "") +
Yes, that looks better, indeed :-)
I suppose it's ok to transform "FieldTable" as well as "string".
Re: Small performance issue
Posted by Kim van der Riet <ki...@redhat.com>.
I'll get to this later this afternoon. Thanks for the patch.
There is a function to do this already in CppGenerator: setRef(), which
changes both string and FieldTable to const &. A shorter (but
equivalent) change would be:
- sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") +
+ sb.append(indent + (defineFlag ? setRef(fieldDomainPair[FIELD_DOMAIN]) + " " : "") +
Kim
On Fri, 2006-12-15 at 18:47 +0100, Jim Meyering wrote:
> Index: src/org/apache/qpid/gentools/CppGenerator.java
> ===================================================================
> --- src/org/apache/qpid/gentools/CppGenerator.java (revision 487512)
> +++ src/org/apache/qpid/gentools/CppGenerator.java (working copy)
> @@ -1490,7 +1490,12 @@
> {
> int ordinal = oItr.next();
> String[] fieldDomainPair = ordinalFieldMap.get(ordinal);
> - sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") +
> + String type_str = fieldDomainPair[FIELD_DOMAIN];
> + if (type_str.compareTo("string") == 0)
> + {
> + type_str = "const " + type_str + "&";
> + }
> + sb.append(indent + (defineFlag ? type_str + " " : "") +
> fieldDomainPair[FIELD_NAME] + (initializerFlag ? "(" + fieldDomainPair[FIELD_NAME] + ")" : "") +
> (oItr.hasNext() ? "," : "") + cr);
> }
Re: Small performance issue
Posted by Jim Meyering <ji...@meyering.net>.
Andrew Stitcher <as...@redhat.com> wrote:
> One more modest performance speed up (around 1.5%); unfortunately this
> is in code generated by the java generator so I don't really know where
> to start to fix this:
>
> In the generated file:
>
> BasicDeliverBody.h
>
> The constructor for BasicDeliverBody uses string by value where it
> should use it by constant reference,
>
> I'm not sure if there any other implications of this change, but it's
> worth doing here, and any other code just initialising string can do it
> through a const reference to avoid an unnecessary copy.
>
> [Incidentally I was surprised to see a bare "string" in a header file,
> the name space must be polluted somewhere]
>
> Andrew
>
> viz:
>> class BasicDeliverBody : virtual public AMQMethodBody
>> {
>> ...
>> BasicDeliverBody(ProtocolVersion version,
>> string consumerTag,
>> u_int64_t deliveryTag,
>> bool redelivered,
>> string exchange,
>> string routingKey
>> ) :
>> AMQMethodBody(version),
>> consumerTag(consumerTag),
>> deliveryTag(deliveryTag),
>> redelivered(redelivered),
>> exchange(exchange),
>> routingKey(routingKey)
>> { }
>> ...
>> }
>
> should be:
>
> class BasicDeliverBody : virtual public AMQMethodBody
> {
> ...
> BasicDeliverBody(ProtocolVersion version,
> const string& consumerTag,
> u_int64_t deliveryTag,
> bool redelivered,
> const string& exchange,
> const string& routingKey
> ) :
> AMQMethodBody(version),
> consumerTag(consumerTag),
> deliveryTag(deliveryTag),
> redelivered(redelivered),
> exchange(exchange),
> routingKey(routingKey)
> { }
> ...
> }
Hi Andrew,
When you suggested that, it rang a bell with me, since I'd looked into
removing some of the -Wshadow warnings, and those generated constructors
is a big source of the offenders. So I just happen to know how to do what
you want. Here's a patch that does it. There's probably a cleaner way to
do it, since I'm no java guru, and spent only an hour or so working on the
-Wshadow business, but this "works for me". FWIW, this induces changes
in most of the gen/*Body classes, not just the one you mentioned.
2006-12-15 Jim Meyering <me...@redhat.com>
* src/org/apache/qpid/gentools/CppGenerator.java: Use a type
of "const string&", rather than "string", in all automatically
generated constructors. Suggested by Andrew Stitcher
Index: src/org/apache/qpid/gentools/CppGenerator.java
===================================================================
--- src/org/apache/qpid/gentools/CppGenerator.java (revision 487512)
+++ src/org/apache/qpid/gentools/CppGenerator.java (working copy)
@@ -1490,7 +1490,12 @@
{
int ordinal = oItr.next();
String[] fieldDomainPair = ordinalFieldMap.get(ordinal);
- sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") +
+ String type_str = fieldDomainPair[FIELD_DOMAIN];
+ if (type_str.compareTo("string") == 0)
+ {
+ type_str = "const " + type_str + "&";
+ }
+ sb.append(indent + (defineFlag ? type_str + " " : "") +
fieldDomainPair[FIELD_NAME] + (initializerFlag ? "(" + fieldDomainPair[FIELD_NAME] + ")" : "") +
(oItr.hasNext() ? "," : "") + cr);
}
Here's the list of changed files.
The result does compile.
gen/AccessRequestBody.h | 2 +-
gen/BasicCancelBody.h | 2 +-
gen/BasicCancelOkBody.h | 2 +-
gen/BasicConsumeBody.h | 4 ++--
gen/BasicConsumeOkBody.h | 2 +-
gen/BasicDeliverBody.h | 6 +++---
gen/BasicGetBody.h | 2 +-
gen/BasicGetEmptyBody.h | 2 +-
gen/BasicGetOkBody.h | 4 ++--
gen/BasicPublishBody.h | 4 ++--
gen/BasicReturnBody.h | 6 +++---
gen/ChannelAlertBody.h | 2 +-
gen/ChannelCloseBody.h | 2 +-
gen/ChannelOpenBody.h | 2 +-
gen/ConnectionCloseBody.h | 2 +-
gen/ConnectionOpenBody.h | 4 ++--
gen/ConnectionOpenOkBody.h | 2 +-
gen/ConnectionRedirectBody.h | 4 ++--
gen/ConnectionSecureBody.h | 2 +-
gen/ConnectionSecureOkBody.h | 2 +-
gen/ConnectionStartBody.h | 4 ++--
gen/ConnectionStartOkBody.h | 6 +++---
gen/DtxStartBody.h | 2 +-
gen/ExchangeDeclareBody.h | 4 ++--
gen/ExchangeDeleteBody.h | 2 +-
gen/FileCancelBody.h | 2 +-
gen/FileCancelOkBody.h | 2 +-
gen/FileConsumeBody.h | 4 ++--
gen/FileConsumeOkBody.h | 2 +-
gen/FileDeliverBody.h | 8 ++++----
gen/FileOpenBody.h | 2 +-
gen/FilePublishBody.h | 6 +++---
gen/FileReturnBody.h | 6 +++---
gen/QueueBindBody.h | 6 +++---
gen/QueueDeclareBody.h | 2 +-
gen/QueueDeclareOkBody.h | 2 +-
gen/QueueDeleteBody.h | 2 +-
gen/QueuePurgeBody.h | 2 +-
gen/StreamCancelBody.h | 2 +-
gen/StreamCancelOkBody.h | 2 +-
gen/StreamConsumeBody.h | 4 ++--
gen/StreamConsumeOkBody.h | 2 +-
gen/StreamDeliverBody.h | 6 +++---
gen/StreamPublishBody.h | 4 ++--
gen/StreamReturnBody.h | 6 +++---
gen/TestStringBody.h | 4 ++--
gen/TestStringOkBody.h | 2 +-
gen/TestTableOkBody.h | 2 +-
48 files changed, 78 insertions(+), 78 deletions(-)
Re: Small performance issue
Posted by Alan Conway <ac...@redhat.com>.
You can check with Kim but I think you need to modify something under
qpid/gentools/templ.cpp/
On Fri, 2006-12-15 at 14:39 +0000, Andrew Stitcher wrote:
> One more modest performance speed up (around 1.5%); unfortunately this
> is in code generated by the java generator so I don't really know where
> to start to fix this:
>
> In the generated file:
>
> BasicDeliverBody.h
>
> The constructor for BasicDeliverBody uses string by value where it
> should use it by constant reference,
>
> I'm not sure if there any other implications of this change, but it's
> worth doing here, and any other code just initialising string can do it
> through a const reference to avoid an unnecessary copy.
>
> [Incidentally I was surprised to see a bare "string" in a header file,
> the name space must be polluted somewhere]
>
> Andrew
>
> viz:
> > class BasicDeliverBody : virtual public AMQMethodBody
> > {
> > ...
> > BasicDeliverBody(ProtocolVersion version,
> > string consumerTag,
> > u_int64_t deliveryTag,
> > bool redelivered,
> > string exchange,
> > string routingKey
> > ) :
> > AMQMethodBody(version),
> > consumerTag(consumerTag),
> > deliveryTag(deliveryTag),
> > redelivered(redelivered),
> > exchange(exchange),
> > routingKey(routingKey)
> > { }
> > ...
> > }
>
> should be:
>
> class BasicDeliverBody : virtual public AMQMethodBody
> {
> ...
> BasicDeliverBody(ProtocolVersion version,
> const string& consumerTag,
> u_int64_t deliveryTag,
> bool redelivered,
> const string& exchange,
> const string& routingKey
> ) :
> AMQMethodBody(version),
> consumerTag(consumerTag),
> deliveryTag(deliveryTag),
> redelivered(redelivered),
> exchange(exchange),
> routingKey(routingKey)
> { }
> ...
> }
>
>