It is pre-compiling apps from java to native executables. This comes from the ART runtime which is the default in Lollipop and newer. Google for "android ART"
I think this is a HUGE problem, and that somebody is going to die because they're unable to call 911 while the phone is "optimizing"
Allegedly in Android N this will be much faster. When I upgraded my Nexus 9 to N this step was probably less than 30 seconds long. I almost didn't even notice it.