-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Use post object in post date block #47997
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Flaky tests detected in 5e28160. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4158836622
|
|
I don't know how to review this to confirm that it is a performance improvement, can you explain it in more detail? |
@carolinan That is the point. By calling |
|
Please consider that for someone who is unfamiliar with the tools you are using, the image has no context. |
What information do you need here? I have provided detail of why this is faster and provided a screenshot of why that is the case. |
|
@spacedmonkey Thanks for the pull request, I believe you're on to something here. The issue is that you're leaving out a lot of context (starting with not giving any info beneath the "Why?", "How?" and "Testing Instructions" sections which are there for a reason) which makes it hard to verify the issue for reviewers.
What is "this"? How many is "lots of calls"? What functions are "many functions"? Not trying to be annoying here, but this info you're now leaving out is what would paint a complete picture.
Can you specify the 5 places that are now calling get_post when they don't have to? And specify "a lot of code"?
As @carolinan pointed out, and I can confirm, the screenshot provided is not providing any additional information to anyone not familiar with the tool you've used. While it's undoubtedly clear to you, personally I have no idea what information the screenshot should convey. E.g. what do the percentages mean? Anyone can dig into the code and probably find out themselves, but that's not doable for every single pull request. I hope you understand and are willing to provide some more context and information. |
|
@spacedmonkey I trust you. But I can not do a code review if I do not fully understand it. |
|
@thomasdevisser @carolinan As I have said, not sure what more context I can give. But I will try. This change has not functional changes in it and will not see anything unless you run a php profiler against it. This is not to test other than run a your favourite profiling tool against. Why is this code better than before. Simple, instead of passing an id, and running |
|
Like @carolinan said Here you no longer need to get the instance, which would indeed result in better performance. |
It does not reduce the number of calls to get_post, but lookups to cache and creating on new post objects. If you give it a object and doesnt need to lookup by id and create a new post. |
|
@joemcgill @felixarntz Can you take a look at this PR? This is a very simple, instead of creating 4 new post objects, create one and pass it in. Quick and easy. |
|
@spacedmonkey The change looks good and should certainly improve performance, in theory. Though from looking at it, I would think this is a micro optimization - which doesn't mean that we shouldn't do it, but there would be 1000s of similar fixes possible in core, and then the question is how valuable is it to tackle all of them vs focusing on larger areas of improvement. Can you share what % of overall processing time this improves e.g. on a page that has 1 or 2 |
This is a micro optimization and does not require this much thought or review. Just found this while working on other things and decided to fix it. There are likely MANY MANY more like this. But let's do this a lots of PRs, as much it easier to review and test. |
joemcgill
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks fine to me, but I agree with @felixarntz that we should evaluate the actual performance benefit in terms of wall time/memory saved by this type of change before refactoring all the places that functions in WP can accept a post ID and a post object where a post ID is being passed.
It is a simple change, but like I mentioned we could make 1000s of those changes. The question is whether it's worth it. Every change still has at least a tiny chance for breakage. And there's also the aspect of our time investment into those little fixes - is this type of micro optimization worth changing as many instances in core as we can to pass objects rather than IDs? I think we should still make an assessment of how beneficial this truly is before going down that rabbit hole. |
|
@felixarntz I understand everything you're saying, and I fully agree that it might not be beneficial to do the 1000 PRs; but it feels like you're saying it's either/or. Either we do all 1000 or nothing. Why not just merge this one and if someone finds another, we merge that one as well? Without actively looking for every single occurrence. |
|
We could and maybe should of course still do an assessment for wether or not we're gonna actively look for these kind of refactors over the entire codebase. |
|
@tomdevisser I'm not saying we should do all or nothing. But I would still like us to get a better idea whether this brings any notable real improvement or is just more of a hypothetical one, for the reasons I mentioned above. For example, if the outcome was that we would need to change a million instances of this call to get a 1ms load time improvement, it's probably just not worth working on this. But if the outcome was that this change brings a consistent 0.1ms or maybe even 0.01ms improvement, that's a whole different story, and then it would be more beneficial. It all comes down to: How long does it take to run |
@felixarntz I hear you, really. It just feels like discussing this has already taken time in which we could've merged this code (that's already been reviewed and ready to merge) 10 times. 😬 I agree on almost everything you're saying, just not the "worth it" and "takes time" argument. Might be naive as a new contributor, but even if this changes the performance by 0.00001%, merging it would've taken less time than this discussion. 😅 I feel like this going back and forth isn't worth it for this issue, although it would be for a bigger assessment. |
|
@tomdevisser I'm not meaning to "discuss" this - I am simply asking to make an actual performance assessment about this change before we move forward with it. |
|
@felixarntz All right. I would say, merge this one and create a new issue to do the assessment to decide whether or not to do this on a bigger scale instead of stalling this PR. But I'll leave it from here, cause I get the feeling you've made up your mind and are digging your heels in. Good luck with the follow up. |
|
@tomdevisser When you say "stalling this PR", it sounds like this performance analysis would take some time, which I don't think is the case. It just needs to be done, I'm sure it'll take less than 1 hour to assess the impact of this change and the cost of There is no rush in merging this. This won't make it into WordPress 6.2 (since it is too late in the release cycle for enhancements like this to be merged), and WordPress 6.3 is a few months away. I personally believe we should assess changes before we commit them, not afterwards. There's also always a risk that otherwise such a follow up never happens. |
|
@felixarntz Got it, thanks for specifying. Have never done one before so I have no idea how much work it would be. Sorry if it came across wrong, there's a language barrier (as I'm Dutch) that can be tough when there's a disagreement, but I'm trying. 🙂 |
|
@tomdevisser No worries at all! I'm German myself, so apologies if anything didn't come across right. 🙂 |
|
Closing this ticket, as this discussion is unproductive. |
|
@spacedmonkey Could you clarify what you mean by "this discussion is unproductive"? All I'm asking for is that we assess this change in terms of its actual performance impact before just moving forward with it. I'm not at all against this change, but I think we should get a better idea about whether this is a micro optimization or an optimization that is actually worth it. Most importantly, what is the cost of a |
|
@felixarntz Hi Felix, I sent you a message on the MWP Slack about this measuring of performance, if you have some time I'd love to hear from you. |
|
Reopening this and doing some performance checks. First test, after performing the suggested approach by @felixarntz:
string(55) "Ran get_post() 100000 times in 0.15558886528015 seconds" |
|
@aristath, @oandregal, I know you've also been doing profiling for the PHP side of the block editor. Maybe you can point @tomdevisser in the right direction on how to profile this branch vs. |
|
Also tested this suggested approach by @felixarntz.
Results before: Results after: So it looks to me like there's a slight regression in performance, but not sure if I'm reading the results correctly? |
|
@tomdevisser Based on your data, I would say this looks neither like a notable regression nor like a notable improvement. There's a good chance that that's actually the case. But to rule that out, we may want to measure with a larger dataset. Performance metrics vary, even between testing the exact same thing multiple times, as this data confirms once again. To potentially counter that, we need to test far more often, let's say 100 times or even 1000 times. Obviously that cannot reasonably be done manually, so we'd need to go with an automated approach. For example, use the Performance Lab plugin's Server-Timing API (see WordPress/performance#553) to capture the results in a response header and then use a script like https://github.com/GoogleChromeLabs/wpp-research/tree/main/cli#benchmark-server-timing to trigger requests, extract the header and compute percentiles/median. Maybe we'll see a performance improvement with that - maybe not. If the latter, it would mean that the impact is extremely small. We can of course argue based on the code change and our experience as developers that this is a performance enhancement, which I definitely don't disagree with. But I would also personally not consider this a priority then, especially as it does open a can of worms with tons of similar code examples present in WordPress core. |














What?
In the post date block, this results in lots of calls to
get_postas post_id is passed on many functions. Instead of using a id, get it once and reuse that.Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast