Started a PR at https://github.com/xwiki/xwiki-platform/pull/3537 . Note that merging this PR won't be enough to fix this issue, but it should still consist in a noticeable improvement .