Some optimizations and add more perf tests