nip2 performs three useful optimisations on expressions. First, it finds and removes common sub-expressions in functions. So for example:
will only evaluate a + b once. This can save a lot of time if a or b is a large image.
Second, nip2 detects arithmetic operations on unsigned char images, and replaces them with look-up tables. For example:
Provided campin.v is an 8 bit image image, this expression will evaluate with a single call to im_maplut().
Finally, nip2 has a VIPS operation cache. It memorises the arguments to the last few hundred calls to VIPS, and the result each call gave. Before calling VIPS again, it checks to see if there is a previous call with the same arguments and if there is, uses the result it obtained last time.