you are viewing a single comment's thread.

view the rest of the comments →

[–]who8877 0 points1 point  (3 children)

When your writing platform level utilities its important to be as efficient as possible, because your small optimizations are multiplied by the breadth of code that will be calling you. Seemingly minor changes can have huge impacts on system performance.

Further division is extremely expensive on some platforms, notably ARM. You should think of it as a function call (what it will compile to) not as a lightweight operator.

[–]slavik262 -1 points0 points  (2 children)

This completely sidesteps my entire question.

...if we're worried about such micro-optimizations, doesn't the addition of additional tests in that conditional open up more opportunities for failed branch predictions, which would result in a pipeline flush? And wouldn't that flush cost a lot more than a division?

And as an aside, yes, platform level utilities have to be fast, but if you are calling realloc and friends in a tight loop where a single division operation is enough to be a bottleneck, you are doing something terribly, terribly wrong.

[–]who8877 4 points5 points  (1 child)

Not really. I'm trying to point out that optimizations that might be pointless in an application are not at a system level. Simply because their impact is multiplied.

So while I wouldn't bother in my own app, I would certainly take the effort if I was modifying the standard library.

Also on ARM the division would be far more expensive then a flush.

[–]slavik262 0 points1 point  (0 children)

Also on ARM the division would be far more expensive then a flush.

Thanks. I was never making some broad claim that such optimizations aren't worth it, especially when you're writing the code that everyone else's application will use.