1. optimize similarity calculation