Bring a few perf patches to 3-0-github from 2-3-github

cc @github/rails3 @github/perf