Do shortcodes affect performance? each plugin using this technique has to parse post/page content looking for the shortcode? If so, it would be better to limit as much as possible shortcode-based plugins?
You need to look at this from a couple of perspectives and then you have to weigh the odds against each other
In general, shortcodes will be slower (we are talking milliseconds here) as they need to be parsed and processed by the shortcode handler.
[my_shortcode] in post editor
Shortcodes in general are quite useful and usally outweigh the fact that they tend to be tad slower than just hardcoding a function and calling it in the desired template. Shortcodes are portable (that is why they should be in a plugin) which makes them excellent for usage between themes. More so, you do not need to alter any template in order to do something special in a template, you can simply drop the shortcode into the post editor's content meta box and your done.
For convenience and ease of use, shortcodes are definitely the way to go here, and all the positives here outweigh the loss in a mere few milliseconds of time due to not using a spaghetti callback function on its own
do_shortcode() hardcoded in a template
This is where I would draw the line, if you need to call a shortcode via
do_shortcode(), then you are doing it wrong. As I said, shortcodes are a tad slower, so here it would be way better to just write a simple function, drop it into a plugin (which is recommended for portability) or
functions.php, and then call the function into your template.
Either way, you will have to alter the template to either call your shortcode or the function or even class which you created. This is why, IMHO, you should not be using shortcodes, but rather a simple function or a class which is a bit faster.
Should you stay away or limit the use of shortcodes? The answer is simple, it all depends on usage as described above. Just a final note, if you are going to call multiple shortcodes within a page, try to limit those by combining features you need into one solid, clever shortcode which can do everything you want.
Before I lay my pen down, I want to leave you with this, download and install the Query Monitor plugin. I personally feel that every developer should have this plugin installed on his/hers local test enviroment. This plugin will tell you excatly how many queries are being made, time take to make those queries, and it will also tell you how much time it took to load a specific page.
There are several aspects and as always, performance is something that have to be taken in a context. Pieter's answer gives you one - "do you even have a (better) way to achieve the required functionality". going beyond that, there are some facts that is worth to keep in mind
- Modern PHP is fast. It is never a good thing to write inefficient code but it is probably not worth wasting too much time trying to optimize the internal working of PHP (example single quote vs double quotes)
- The time consuming part of using regular expressions to detect and parse shortcodes is not always with parsing the text itself but in generating the internal "parsing machine" which is used in the parsing of the text. PHP helps here by caching the machines.
- bloat is bloat, and bloat usually impacts performance in some way. In general you could "turn off" shortcodes that you do not use and get the relevant "parsing machine" to be smaller and therfore faster. The thing to be careful about if you actually go that way, is to make sure that the bloat removal code do not take more time to execute than the impact of the mere existence of the useless shortcodes.
If your not called shortcodes, this means they not called their functions and therefore it no affect performance of your website.
Also you can use static class and variables to reduce load to your site. Every shortcode will be use function only one time, independently how many times you call it.