lots of performance tuning (combined in 1 commit)
Merge branch 'perf.korny'