Collapsing diff in large MR takes a lot of time
### Summary
Collapsing a file in a merge request takes several seconds (~15 seconds) and pegs one CPU the whole time.
### Steps to reproduce
1. Open https://gitlab.com/leipert/test-project/merge_requests/2
2. Go to the diff tab. Wait until page is loaded completely
3. Collapse the first file
### What is the current *bug* behavior?
It takes several seconds to collapse the file
### What is the expected *correct* behavior?
It should collapse the file instantly.
### Relevant logs and/or screenshots

- Start of collapse: 2.8s
- End of collapse: 17.97s
issue