perf

Preliminary performance optimizations based on profiling trace submitted by a user.