On Fri, Oct 17, 2008 at 11:39:40AM +0100, Daniel P. Berrange wrote: > Looking at the libvirtd objects with pfunct I knoticed that the method > remoteDispatchClientRequest in remote.c was unusually large > > size: 11497, variables: 169, inline expansions: 159 (5144 bytes) > > Listing variables present its clear why - for every RPC call, we have > a pair of local variables declared for the structs for the reply and > response. Following by a memset() call for every single one. > > Any single call to this method only processes one RPC call, so I figured > we could collapse all these variables down into a single pair by using > a union for all args, and a union for all replies. > > This patch does just that with the result that the method changes to: > > /* size: 1386, variables: 10, inline expansions: 4 (89 bytes) */ > > If you want to see details list of variables before and after results > then run > > $ pfunct -f remoteDispatchClientRequest libvirtd-remote.o > > NB pfunct is in the 'dwarves' RPM, along with some other interesting > tools like 'pahole' > > In doing this I noticed that the dispatch function is O(n) on the > number of RPC calls we have defined. This isn't a serious bottleneck > since 'n' isn't very large, but while doing the refactoring for the > union stuf, it was easy enough to also change it to declare an array > of all the dispatch methods, which could simply be indexed on the > RPC call number. This changes it to O(1) time to dispatch. The patch tends to generate headaches, and I still can't grok perl, but what I recognized looks fine, and the principles sounds good. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@xxxxxxxxxxxx | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list