Fix two serious perf regressions.