Code diagram optimization