Question is quite simple - Does checking the actual parameters given to a function incur a performance penalty?
Exported library functions usually tend to check actual parameters passed by user code:
if (arg1 == NULL || arg2 == NULL)
return -EINVAL;
Does this check incur a performance penalty? I tried optimizing some library code by removing these checks from some of the exported function (relying on me being a well behaved user and always passing valid parameters) but I noticed no real improvement.
My first guess would be that branch prediction on modern processors will assume the if branch is not taken and proceed with the code with no real penalty. If this is indeed the reason - what are the limits of such branch prediction mechanisms? Is there any scenario in which eliminating these checks would improve performance? How does this change between a native compiled language such as C and an interpreted or VM language such as Python and Java?
BTW - I realize the importance of checking runtime parameters. I'm just interested on the performance aspect.