-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize AMP_Tag_And_Attribute_Sanitizer::get_missing_mandatory_attributes() #4991
Optimize AMP_Tag_And_Attribute_Sanitizer::get_missing_mandatory_attributes() #4991
Conversation
Nice! That's is what I am talking about! |
Plugin builds for 05f74ed are ready 🛎️!
|
OMG |
It is noticeably (!) faster now when navigating the AMP site. |
For some context here, mea culpa on introducing the performance problem in #929 via 372412b#diff-ee41b32e64c90445a71328ca93cfa799R391 for the plugin's v0.7 version. The performance issue is greatly amp-lified when Xdebug is enabled, and for that reason we added a much-maligned admin notice (#3198) which we moved a Site Health test (#4432). I still think there is value for having that Site Health test when |
Co-authored-by: Weston Ruter <westonruter@google.com>
Cherry-picked onto |
Summary
While doing an initial test run with Blackfire (see #3361), I noticed the following:
Of the 2.61s AMP page generation time, the
AMP_Tag_And_Attribute_Sanitizer::get_missing_mandatory_attributes()
method was accounting for more than 50% of the execution time.It was calling:
substr()
DOMElement::hasAttribute()
AMP_Tag_And_Attribute_Sanitizer::check_attr_spec_rule_mandatory()
As you can see from the flamegraph, the AMP generation is disproportionally large because of that:
The problem is that the method loops over all nodes, and then for each of them loops over all specs, and then checks whether something is mandatory.
The current PR addresses this by extracting one conditional out of
AMP_Tag_And_Attribute_Sanitizer::check_attr_spec_rule_mandatory()
and puts it as the first check withinAMP_Tag_And_Attribute_Sanitizer::get_missing_mandatory_attributes()
. This check is the most important one: is this spec mandatory? The entire rest of the logic can be skipped if that is not the case.Here's the result:
The method has dropped out of the captured graph of Blackfire, meaning it accounts for less than 1% of the execution time in any way. To get a more detailed overview, I'd have to re-run with
blackfire curl --debug
to disable this pruning, but it doesn't allow me to do that right now it seems.Anyway, the function went from being more than 50% of the total page generation time, to being insignificant.
The flamegraph also looks completely different now:
Checklist