Consider "DigitalWrite()" on Arduino.
Yeah, it's 10x slower, Because it maps virtual pin numbers...
Well, more like 30x slower, because it does other things as well.
- Maps pins numbers to Port/Bit.
- Since Port and Bit are now variables, one has to used indexed memory instructions rather that the quicker in/out, or the single-bit set/clear instructions.
- And that has to be wrapped in code to make it atomic.
- And they'll check to see whether the pin is doing PWM (attached to a timer, rather than GPIO), and turn that off if necessary.
In a way, digitalWrite() can serve as an example of both the good and bad aspects of "abstraction."
On the one hand, it's a pretty brilliant API for the target audience, allowing them to avoid learning about bitwise arithmetic. It's clear, obvious, and "easily portable" to nearly any architectures. And as Bruce said, it's almost always "plenty quick" (especially compared to Arduino's predecessors like Stamp Basic or Basic52.)
BUT... all that extra processing can be painful when you start using it in more complex situations. Consider the shiftOut() function, which does a synchronous serial output of a byte on a data pin and clock line. It is currently implemented using digitalWrite(), which means that all those checks and translations are done about 14x more times than they need to be. :-( (but good luck guessing whether you can speed it up and still have all the applications using it still work with the 30x faster clock.)
Then there are the side effects. On an AVR, a digitalWrite() to a pin in INPUT mode turns on an internal pullup. But that's not how most 32bit microcontrollers work. SOME 32bit cores (SAMD, for instance) carefully duplicate this behavior (MORE overhead.) Others (Renesas) ... not so much. (and not all platforms do the PWM check, either.)
And you run into the problem of multiple layers of abstractions. The Uno R4 (Renesas) Arduino core is built on top of Renesas's "fsp" HAL library. It ALSO has an abstraction for "pins." So the Arduino code translates and Arduino Pin to a Renesas Pin, and the the Renesas code translates that to the actual port addresses and bitmasks (and not very well, either.)
Sigh. It's all
Very Frustrating, for the sort of intellect that cares about such things.
And as many others have said, this "bloat" is not at all "new", and neither is the "quality problem." I've been doing SW development for a long time, and I'm pretty sure that there was NEVER a time when SW quality was "assured." Nowadays there are SO many developers, users, and attackers that quality problems are more dramatic, but...
And like many other products, the consumer demand is for fast and cheap, rather than "top quality."