Il mar 19 nov 2024, 21:07 Peter Xu <pet...@redhat.com> ha scritto: > > Ah, that was supposed to be the difference between type_register() and > > type_register_static(). > > Ah... looks like they're the same now? As type_register_static() looks like > a wrapper of type_register(). >
And pretty much have always been... Zhao looked into it recently. > Perhaps type->name could be allocated with g_intern_string()? And then if > > object_dynamic_cast() is changed into a macro, with something like > > > > #define qemu_cache_interned_string(s) \ > > (__builtin_constant_p(s) \ > > ? ({ static const char *interned; \ > > interned = interned ?: g_intern_static_string(s); }) \ > > : g_intern_string(s)) > > > > as the third parameter. This allows object_dynamic_cast() to use a simple > > pointer equality for type name comparison, and the same can be applied to > > object_class_dynamic_cast(). > > Interesting to know this facility! Though, IIUC this may: > > - For builtin-consts, it grows 8 bytes for each call sites on the binary > generated, even if (I think...) most of the sites are slow paths, and > there're plenty of such calls.. > Right, but all the fast paths will be here. Only a few will be of course. - For non-builtin strings, g_intern_string() will add one more hash > operation for the whole string (and per discussed previously, looks > like the string can be not always short..). > Yes, but non-const strings should be *really* rare and not fast paths. So I'm not 100% sure yet if this is what we want. > > Do we have known places that we care a lot on object[_class]_dynamic_cast() > performance? The easiest way to check is probably to print the type of every successful object_dynamic_cast and object_class_dynamic_cast. I suspect the result will be virtio-blk-device and/or scsi-hd, but maybe those already do an unsafe cast (pointer type cast) instead of object_dynamic_cast. I can give it some measurement if there is, otherwise I'm > guessing whatever changes could fall into the noise. Yes, probably. At most you can identify if there any heavy places out of the 34000 calls, and see if they can use an unsafe cast. Paolo