Performance on Parallels shared folders
This is all very anecdotal, but the 'best' number of cores to assign for maximum performance is 'the actual number of cores, excluding virtual cores'. In your case 8. You could probably get away with giving it more RAM too. 8GB is safe out of 16, though you might get away with 12.
You'll never get a VM to compile as fast as a hardware install, if all else is like for like. Compiling is always going to work the machine hard - or it's not going as fast as it can. The trick of using all the 'real' cores is that you leave yourself enough breathing room to still be able to work without hinderance on the Mac side at the same time.