Performance patch: mostly from Patrick perf Dowling branch.