Ungrouping synthesized modules in Synopsys Design Compiler for better synthesis results
Does ungrouping different designs optimize mostly around the
  boundaries or will optimize the whole design regardless of whether
  each smaller module has been synthesized before or not?


There is no difference between an RTL design and a post-synthesis netlist. Design Compiler tries to optimize both of them as long as the constraints (e.g. dont_touch) and synthesis options (ungrouping, boundary optimization etc.) permit. DC also has an option for the optimization strategy, I'll show below.


  If it optimizes the design as a whole, is there an advantage to
  synthesizing smaller modules first?


It's hard to predict. Different options and optimization strategies don't give the same results in all cases. I have experienced that sometimes ungrouping a whole project gives worse results (timing, area etc.). The best thing to do is to try a few sets of options and to continue with the best resulting one.


  Is there a set of DC commands that can achieve this?


I haven't tried myself, but there are two strategies to optimize a design.


Each output in my_module is optimized individually.

set_flatten -design &lt;my_module&gt; -minimize single_output

The design is optimized as a whole.

set_flatten -design &lt;my_module&gt; -minimize multiple_output