| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…iming controlled by a WP Admin screen.
| add_action( "load-{$hook_suffix}", 'perflab_load_server_timing_page' ); | ||
| } | ||
|
|
||
| return $hook_suffix; |
There was a problem hiding this comment.
What are you returning this for? This is hooked into an action right?
Sorry, something went wrong.
There was a problem hiding this comment.
Right, this would only be useful for test coverage, which I'm planning to add.
Sorry, something went wrong.
| function perflab_sanitize_server_timing_setting( $value ) { | ||
| if ( ! is_array( $value ) ) { | ||
| return array(); | ||
| } | ||
|
|
||
| // Ensure that every element is an indexed array of hook names. | ||
| return array_filter( | ||
| array_map( | ||
| static function( $hooks ) { | ||
| if ( ! is_array( $hooks ) ) { | ||
| $hooks = explode( "\n", $hooks ); | ||
| } | ||
| return array_filter( array_map( 'sanitize_key', $hooks ) ); | ||
| }, | ||
| $value | ||
| ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
This could do with a unit test IMO.
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, I haven't added unit tests yet, but definitely planning to do so.
Sorry, something went wrong.
|
Just from looking at the screenshot alone it is not clear what exactly would be measured. Is it the time since the last hook (i.e. do_action(wp_loaded) *start* ... *stop* do_action(init), or the duration of all the functions hooked into it (i.e. *start* ... do_action( xyz ); *stop*). Looking at https://gist.github.com/felixarntz/63c05392dbf7d51cc7f8f4a424b1ff39, it seems to be the latter, but would be nice to clarify that in the UI with a clearer description. |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @felixarntz for the PR, If anyone add duplicate value in Actions or Filters then it shows error.
For ex.
init wp_loaded init
Sorry, something went wrong.
|
Thanks @swissspidy @mukeshpanchal27 for the feedback.
I'll work on some test coverage now, mostly relevant for the WP Admin UI. |
Sorry, something went wrong.
Sorry, something went wrong.
| * Any duplicates across a group of hooks are removed. | ||
| */ | ||
| return array_filter( | ||
| array_map( |
There was a problem hiding this comment.
Should this be checking whether the keys are those which are allowed, i.e. benchmarking_actions and benchmarking_filters?
Sorry, something went wrong.
There was a problem hiding this comment.
Good idea, updated in 7f99021
Sorry, something went wrong.
| }, | ||
| $hooks | ||
| ) | ||
| ) | ||
| ) | ||
| ); | ||
| }, | ||
| $value | ||
| ) |
There was a problem hiding this comment.
There is a lot of nesting happening here. Not a problem, but just makes it a bit hard on the eyes. Not a blocker.
Sorry, something went wrong.
There was a problem hiding this comment.
Reduced the nesting a bit in 7f99021
Sorry, something went wrong.
|
For some reason when I add a filter to get Server-Timing for, e.g. the_content, I'm getting a PHP notice: Notice: Function Perflab_Server_Timing::register_metric was called incorrectly. The method must be called before or during the perflab_server_timing_send_header action. Please see Debugging in WordPress for more information. in /var/www/html/wp-includes/functions.php on line 5865 I don't get it for when I add actions, however. 😕 |
Sorry, something went wrong.
|
@westonruter That's because the the_content hook runs after the header is output. So hooks like that can only be used if output buffering is enabled. Maybe we open a separate PR to add a checkbox to allow controlling that as well? That would make that bit easier as well, without the need for another one-liner plugin. |
Sorry, something went wrong.
Oh, of course. Same as mentioned in #784 (comment). What do you think about the presence of any Server-Timing hooks to automatically cause output buffering to be enabled automatically? That would prevent others from getting tripped up the same way I did. |
Sorry, something went wrong.
|
@westonruter I think it would be better to have an explicit setting for it. To clarify the limitation when output buffering is not enabled, I have added a message for it in fd41db1 (see also the updated screenshot in the PR description). Once we add a setting control for it, we can consider toggling that with JS based on the checkbox. |
Sorry, something went wrong.
| static function() { | ||
| ?> | ||
| <p> | ||
| <?php esc_html_e( 'In this section, you can provide hook names to include measurements for them in the Server-Timing header.', 'performance-lab' ); ?> |
There was a problem hiding this comment.
Since the Server-Timing header is not something that should be translated, I'd recommend using sprintf with a placeholder here (+ a translator comment of course).
Sorry, something went wrong.
| <br> | ||
| <?php | ||
| echo wp_kses( | ||
| __( 'Since the Server-Timing header is sent before the template is loaded, only hooks before the <code>template_include</code> filter can be measured.', 'performance-lab' ), |
There was a problem hiding this comment.
I'd use sprintf with a placeholder for template_include so that it does not get translated
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM, just two i18n notes
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @felixarntz for the updates.
I still reproduce #784 (review) error. Could you please take a look. Thanks.
Sorry, something went wrong.
Maybe it was because you had those settings saved from before? The actual behavior from having duplicate hooks was not changed, but I added sanitization to strip duplicate values. So can you please try to go to the Tools screen again and re-save? It should result in the duplicates being stripped. |
Sorry, something went wrong.
I'd like to propose Output Buffering as a new module. This module would be to explore implementation of Core-43258/Core-58285 while also providing an easy way to implement the toggle. It will give us an area to explore use of output buffering to make Performance enhancements as well, such as applying LCP enhancements to arbitrary elements not rendered using the normal WordPress mechanisms (e.g. hard-coded images and page builders). cc @joemcgill @kt-12 |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @felixarntz, I test in fresh installation and it working for me.
Sorry, something went wrong.
I'll work on this. |
Sorry, something went wrong.
See #801 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
This PR implements a WP Admin screen Tools > Server-Timing which allows providing action and filter names. Any hook names provided will be measured and exposed in the Server-Timing header in the frontend.
While the Server-Timing API from #553 has been a powerful foundation, it can sometimes be cumbersome to measure specific hooks performance, since it always requires writing custom code. Gists like this one can be used for that, but even with such thing it may be easier to just add the action or filter to a UI instead of having to modify a plugin's code. This PR makes it really easy and gives site owners control about specific hooks to measure.
The new admin screen with example input
Relevant technical choices
Testing
Checklist