`GFForms::ensure_hook_js_output` is degrading performance potentially causing 500s

I’m working on a site for a client that has GravityForms. While debugging some performance problems, I found the GForms::ensure_hook_js_output function. It seems to output buffer the whole content and then throw that content into DomDocument. This has two problems:

  1. It adds load time to every page on the site
  2. One sufficiently large pages it adds an extra layer of output buffering, resulting in extra memory usage. Resulting in a max memory 500 error. In the case I’m debugging this is because of XML sitemaps.

You can suggest to our product team any improvement you wish using the (+) button at the bottom of our roadmap page: Gravity Forms Roadmap - Gravity Forms

That way your request will reach the product team directly and they will be able to consider your request and queue it in the workflow of a future version if it’s accepted.