Is image padding really necessary while using a filter? I do know that we must pad an image while using a filter. But what I am suggesting is that is it really necessary? Can't we just calculate at run time if the current cell/pixel is an edge cell/pixel and then use the padding value directly over there. It might add an overhead to the function but so does the entire padding function.

Only reason I think the padding function should be used is if the padded version of original image is going to be used in many different function which will overtake the overhead of dynamically calculating the edge cell/pixel values(which might never occur). Am I wrong?
Adding code to your filter function to detect and resolve edges implies code running needlessly throughout most of the image. Image area grows quadratically with image size.

Padding grows linearly with image size (as does the perimeter), so adding padding instead of edge-detection code seems a more efficient option.

Also, when adding padding, you are free to choose what to fill the padding with, according to your particular problem. You may choose to fill in with a constant value, or mirror the image, or get overlap data from adjacent images, etc.