Skip to content

Benchmark setup HTML API#30

Draft
sirreal wants to merge 18 commits intotrunkfrom
bench-html-api
Draft

Benchmark setup HTML API#30
sirreal wants to merge 18 commits intotrunkfrom
bench-html-api

Conversation

@sirreal
Copy link
Copy Markdown
Owner

@sirreal sirreal commented Mar 11, 2026

Trac ticket:

Use of AI Tools


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes a foundational benchmarking setup for the HTML API using PHPBench. It integrates the benchmarking tool, configures the WordPress environment for benchmark execution, and provides initial performance tests for the WP_HTML_Tag_Processor and WP_HTML_Processor classes. This will allow for systematic performance measurement and optimization of HTML processing within WordPress.

Highlights

  • Benchmarking Tool Integration: Integrated phpbench/phpbench as a development dependency to enable performance benchmarking within the project.
  • WordPress Bootstrap for Benchmarks: Introduced phpbench-bootstrap.php to properly load the WordPress environment, including global variables and constants, specifically for benchmark execution.
  • PHPBench Configuration: Added phpbench.json to configure PHPBench, specifying the bootstrap file and the directory where benchmark files are located.
  • Code Standard Exclusions: Updated phpcs.xml.dist to exclude benchmark files from specific PHP Code Sniffer rules related to naming conventions and file names.
  • Initial HTML API Benchmarks: Created WpHtmlTagProcessorBench.php with initial benchmarks for WP_HTML_Tag_Processor and WP_HTML_Processor to measure various aspects of HTML parsing performance.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • composer.json
    • Added phpbench/phpbench as a development dependency.
  • phpbench-bootstrap.php
    • Added a new file to bootstrap the WordPress environment for PHPBench benchmarks, including globalizing WordPress variables and defining constants.
  • phpbench.json
    • Added a new configuration file for PHPBench, specifying the bootstrap script and the directory for benchmark files.
  • phpcs.xml.dist
    • Excluded benchmark files in tests/benchmarks/benchmarks/* from PEAR.NamingConventions.ValidClassName.Invalid rule.
    • Excluded benchmark files in tests/benchmarks/benchmarks/* from WordPress.Files.FileName rule.
  • tests/benchmarks/benchmarks/html-api/WpHtmlTagProcessorBench.php
    • Added a new benchmark class for WP_HTML_Tag_Processor and WP_HTML_Processor, including tests for JavaScript custom escape and various HTML parsing scenarios.
Activity
  • This is a new pull request opened for code review, intended to set up benchmarking for the HTML API. Further discussion is directed to the associated Trac ticket.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively sets up the infrastructure for benchmarking the HTML API using PHPBench. The changes to composer.json and phpcs.xml.dist are appropriate, and the initial benchmark file for WpHtmlTagProcessor is well-structured. I have a few minor suggestions in phpbench-bootstrap.php to improve error reporting and remove a redundant line of code. I also have a small style suggestion in the benchmark file itself to align with coding standards.

Comment on lines +21 to +23
if ( ! is_readable( $config_file_path ) ) {
exit( 1 );
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better debugging, it's helpful to output an error message to stderr when the script exits due to a fatal condition. This will make it easier to diagnose setup issues when running the benchmarks.

if ( ! is_readable( $config_file_path ) ) {
	fwri te( STDERR, "Error: Could not read the WordPress test configuration file from {$config_file_path}. Aborting.\n" );
	exit( 1 );
}

Comment on lines +27 to +29
if ( ! is_dir( ABSPATH ) ) {
exit( 1 );
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the check above, adding an error message here would improve debuggability if ABSPATH is not correctly defined or doesn't point to a directory.

if ( ! is_dir( ABSPATH ) ) {
	fwrite( STDERR, 'Error: The ABSPATH ' . ABSPATH . " is not a directory. Aborting.\n" );
	exit( 1 );
}

define( 'WP_MAX_MEMORY_LIMIT', -1 );

$PHP_SELF = '/index.php';
$GLOBALS['PHP_SELF'] = '/index.php';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line is redundant. $PHP_SELF is a global variable, so assigning to it on line 60 is sufficient to set the global value. This line can be removed.

#[Bench\AfterMethods( 'clean_up_processor' )]
#[Bench\ParamProviders( 'provide_script_tag_contents' )]
public function bench_javascript_custom_escape( array $params ): void {
[ $source_text] = $params;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To adhere to common PHP coding standards (like PSR-12) and improve consistency, array destructuring should not have a space before the closing bracket. The standard form is [$var] = $array;.

		[$source_text] = $params;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant