Yeah, people are always scared of derivatives, but they are nearly free. Certainly cheaper than resampling the texture 2 or 3 more times. Like @mattorialist mentioned it’s using data that’s already been calculated, a ddx or ddy is effectively just the cost of a single subtraction, but shared between 4 pixels. Even fwidth is just two subtraction and an add, again shared between 4 pixels.
For to reduce aliasing from using derivatives you can try using ddx_fine instead. Since ddx is calculated for each 2x2 pixel group, the value that ddx returns for all 4 of those pixels is the same. Using ddx_fine it is calculated for each 2x1 pixel group. There’s still a chance for aliasing, but it can help a lot in certain situations.