resolve memory leak and improve performance by precompiling template