Optimize graph generation.