What does it actually do when showing this message on the end of a installation?
During the "optimizing" stage, the system is "prebinding" executables. As per Wikipedia:
Prebinding is a method for reducing the time it takes to launch executables in the Mach-O file format.
Prebinding looks up memory addresses of symbols in libraries that the program is using before the program is launched, and stores this information ahead-of-time, so that the computer need not look up (bind) addresses on each launch.