How does the diff algorithm work?
It uses Myers' O(ND) difference algorithm, the same one git uses by default. It finds the smallest number of added and removed lines that turn the original into the changed text, then compares the words inside each changed line to highlight what exactly differs.