While doing some profiling on Plasma startup I noticed that a significant amount of time is spent loading applets (who would have thought :)), in particular Plasma::PluginLoader::loadApplet().
To make profiling of that easier I made a minimal test case based on an applet set observed in my regular session: https://invent.kde.org/nicolasfella/appletbenchmark
Based on profiling that I have some ideas for performance improvements:
A significant amount of time is spent on finding the C++ plugins that some applets have. This is effectively done using KPluginLoader::findPluginsById, which involves looping over all plugins. To speed that up a cache is maintained. However building the cache is itself quite expensive.
A better solution would be to have a way to determine the plugin file name (or lack thereof) from the KPackage metadata. For KCMs we have a X-KDE-Library key in the metadata, I would suggest we do the same here. This way we can skip the costly plugin discovery and feed the file name directly into KPluginLoader. However we would need to keep compatibility for existing applets until Plasma 6.
Another thing that's quite prominent in the profile is KPluginMetaData::fromDesktopFile(). This is due to the fact that applets installed using plasma_install_bundled_package seem to have no metadata.json so the (costly) conversion needs to happen at runtime. See https://mail.kde.org/pipermail/plasma-devel/2021-July/120525.html for more.