Skip to content
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

gutenberg_parse_blocks( $post->post_content ) takes 135 ms to execute #7337

Closed
manake opened this issue Jun 17, 2018 · 6 comments
Closed

gutenberg_parse_blocks( $post->post_content ) takes 135 ms to execute #7337

manake opened this issue Jun 17, 2018 · 6 comments
Labels
[Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Bug An existing feature does not function as intended

Comments

@manake
Copy link

manake commented Jun 17, 2018

$start = microtime(true);
$blocks = gutenberg_parse_blocks( $post->post_content );
$time_elapsed_secs = microtime(true) - $start;
echo $time_elapsed_secs * 1000;

And every time I call this function this time is increased, for example 5 × 135 ms = 675 ms.

Is there some $wp_query->parsed_blocks or something available?

@manake
Copy link
Author

manake commented Jun 17, 2018

I'm using this until some official response arrives:

function xxx() {
	global $post;
	$GLOBALS['parsed_blocks'] = gutenberg_parse_blocks( $post->post_content );
}
add_action( 'wp', 'xxx' );

I found that pre_get_posts is too early and posts_selection is something unknown to me so I used wp action.

https://codex.wordpress.org/Plugin_API/Action_Reference

@katerlouis
Copy link

I'm curious what gutenberg_parse_blocks is; I can't find an explanation on the webz.

@danielbachhuber
Copy link
Member

@manake Can you share the contents of $post->post_content in a Gist or similar?

@danielbachhuber danielbachhuber added the [Status] Needs More Info Follow-up required in order to be actionable. label Jun 18, 2018
@manake
Copy link
Author

manake commented Jun 18, 2018

I tested it with several $post->post_content. The execution (parsing) time increases in direct proportion to the content's length.

The following gives me roughly 35 ms (PHP 7.0.4, i7, Windows 10):

$blocks = gutenberg_parse_blocks( '<!-- wp:columns {"columns":3} -->
<div class="wp-block-columns has-3-columns">
	<!-- wp:heading {"layout":"column-1"} -->
	<h2 class="layout-column-1">Test</h2>
	<!-- /wp:heading -->

	<!-- wp:paragraph {"layout":"column-1"} -->
	<p class="layout-column-1">TEst</p>
	<!-- /wp:paragraph -->

	<!-- wp:heading {"layout":"column-2"} -->
	<h2 class="layout-column-2">Test2</h2>
	<!-- /wp:heading -->

	<!-- wp:paragraph {"layout":"column-2"} -->
	<p class="layout-column-2">testsetestsetsetsetsetset</p>
	<!-- /wp:paragraph -->

	<!-- wp:heading {"layout":"column-3"} -->
	<h2 class="layout-column-3">Kjsjdf</h2>
	<!-- /wp:heading -->

	<!-- wp:paragraph {"layout":"column-3"} -->
	<p class="layout-column-3">testsetsets</p>
	<!-- /wp:paragraph -->
</div>
<!-- /wp:columns -->' );

Out of curiosity I tried it on PHP 7.1.18, Ubuntu 16.04.1, Intel c2750 and the value oscillates around 10.068893432617 ms while 5 copies raise it to 49.859046936035 ms.

My issue is already somewhat solved (with a workaround) but since WordPress is already running gutenberg_parse_blocks once and my theme/plugin runs gutenberg_parse_blocks again then I thought I'll ask if perhaps WordPress exposes the result somewhere (if this is such a time-consuming function it was worth asking)?

@danielbachhuber danielbachhuber added [Type] Bug An existing feature does not function as intended and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Jun 18, 2018
@danielbachhuber danielbachhuber added this to the WordPress 5.0 milestone Jun 18, 2018
@danielbachhuber danielbachhuber added Framework Issues related to broader framework topics, especially as it relates to javascript [Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f labels Jun 18, 2018
@danielbachhuber
Copy link
Member

Thanks for the additional detail, @manake. I've filed this as a bug for now, to at least get some visibility on it before too long.

My issue is already somewhat solved (with a workaround) but since WordPress is already running gutenberg_parse_blocks once and my theme/plugin runs gutenberg_parse_blocks again then I thought I'll ask if perhaps WordPress exposes the result somewhere (if this is such a time-consuming function it was worth asking)?

I'm not convinced saving the results to some global is the appropriate technical solution. It seems more valuable and important to solve the performance issue.

Related #5967 #5572

@mcsf
Copy link
Contributor

mcsf commented Sep 18, 2018

@manake: Thanks for the report. #8083 recently introduced an all-new parser implementation which should greatly improve performance. I expect this issue to thus be resolved, but feel free to reopen if you're not satisfied.

@mcsf mcsf closed this as completed Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants