Compile Gradient and SurfaceNormal only once
Right now, both the Gradient and SurfaceNormal are compiled at least twice, on as a standalone filter, the other as part of the Contour filter. Change it such that Contour calls these filter than has them.