Topics (by themselves) have very little overhead; if there are no subscribers to a topic, there is no data transferred and therefore no bandwidth used.
The place where I've seen the largest performance penalty for topics that aren't subscribed to is the computation of the data; for example if your node is processing images, in a simple implementation the node performs the image computation even if the result is not used.
Publishing messages incurs a very small amount of processing to serialize the message, but this is negligible for small messages (<1MB in size).
The common solution that I've seen to both of these is to check if there are any subscribers on a topic before publishing, and skipping the processing and publish steps if there are no subscribers. (In C++ you can use the getNumSubscribers()
call on the publisher object)
ROS doesn't provide any direct tools for analyzing the performance hit of the library itself. If you're interested in analyzing CPU bottlenecks, you can run your node in a profiler.
If you're interested in network bandwidth usage, there are lots of good network analysis tools like iptraf and iftop. (nethogs looks interesting too, but I haven't used it personally)
I don't know the full answer, but I'm pretty sure it depends on the topic. Some are on-demand and some aren't. http://answers.ros.org/question/37869...