Opened 5 weeks ago
Last modified 2 weeks ago
#62333 new enhancement
Simplify code structure and optimize conditional logic in REST API controllers
Reported by: | antonvlasenko | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | 6.7 |
Component: | REST API | Keywords: | has-patch |
Focuses: | rest-api, performance, coding-standards | Cc: |
Description
After inspecting the code in the wp-includes/rest-api/
directory, the following minor issues were identified:
- unnecessary local variables;
- static methods called dynamically;
- non-static methods called statically;
- non-optimal order of conditional expressions in
if
statements, impacting performance; - inefficient usage of ternary operators;
- unconsolidated
isset()
andunset()
statements; - redundant
else-if
statements; - use of
count()
to check for empty arrays, impacting performance;
and other related issues.
This ticket is supposed to track patches intended to address these issues.
Change History (14)
This ticket was mentioned in PR #7703 on WordPress/wordpress-develop by @antonvlasenko.
5 weeks ago
#1
- Keywords has-patch added; needs-patch removed
This ticket was mentioned in PR #7704 on WordPress/wordpress-develop by @antonvlasenko.
5 weeks ago
#2
Trac ticket: https://core.trac.wordpress.org/ticket/62333
This ticket was mentioned in PR #7706 on WordPress/wordpress-develop by @antonvlasenko.
5 weeks ago
#3
Trac ticket: https://core.trac.wordpress.org/ticket/62333
This ticket was mentioned in PR #7707 on WordPress/wordpress-develop by @antonvlasenko.
5 weeks ago
#4
Trac ticket: https://core.trac.wordpress.org/ticket/62333
This ticket was mentioned in PR #7708 on WordPress/wordpress-develop by @antonvlasenko.
5 weeks ago
#5
Trac ticket: https://core.trac.wordpress.org/ticket/62333
#6
@
5 weeks ago
Hey @antonvlasenko =- thanks for opening the ticket and PRs.
I'm curious what led you to these refactoring points, are you using a tool to identify these fixes?
Is there some issue you are trying to address / what is your goal with these changes - better compatibility or tooling, or ?
In general, we shy away from refactoring for refactoring's sake in core, see https://make.wordpress.org/core/handbook/contribute/code-refactoring/
@mukesh27 commented on PR #7708:
5 weeks ago
#7
Have you check the performance number before/after?
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
4 weeks ago
#10
@
4 weeks ago
Hi @adamsilverstein,
Thank you for your comment.
There were several goals with these PRs:
- making small performance tweaks;
- making the code stricter, leaving less room for errors;
- fixing some obvious issues, like calling non-static methods statically;
The intention was to make the code stricter and more static-analysis-friendly, as this would help catch more bugs and inaccuracies down the road.
@antonvlasenko commented on PR #7708:
4 weeks ago
#11
Have you check the performance number before/after?
@mukeshpanchal27 I measured the performance improvement after you asked this question.
For example, in the widget controller, the improvement is about 0.6-1.5 microseconds per widget (of course, if certain conditions are met, and it depends greatly on the particular system).
The difference is measureable but minimal.
I expect similar results when measuring other controllers.
Trac ticket: https://core.trac.wordpress.org/ticket/62333