So I was trying to upgrade an older Ansible environment from Ansible 2.7 + Jinja2 2.8 and ran across some severe performance degradation. A template task that used to take about 30 sec to complete across all hosts now takes about 15 min, bottlenecking on the CPU of the management host.
I ran across https://github.com/ansible/ansible/issues/68763 which was part of the issue. However even restricting Ansible to version 2.9.5 we hit another performance issue going from Jinja2 2.8 → 2.9. After bisecting the Jinja2 commits, the culprit is https://github.com/pallets/jinja/commit/d67f0fd4cc2a4af08f51f4466150d49da7798729
Unfortunately I don’t know enough about the Ansible internals and its integration with Jinja2 to understand what’s going on here. Can someone explain why this change would cause such a severe performance impact?