base: use graph when optimizing stuff