Static call optimization

Similar to #1846