Resolve "Performance issues when processing large build traces with Ansi2html"
Port of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10336 for 9-0-stable
The original MR is based on https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10311 so might be better to get that MR in 9-0-stable
first