Optimizing web applications using declarative software rewriting