Closed (fixed)
Project:
Drupal core
Version:
10.3.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
16 Feb 2024 at 10:43 UTC
Updated:
7 Mar 2024 at 09:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
wim leersComment #4
catchThe MR is up, I'm seeing variations though in both the isValid and checksum counts, in what might be both directions, when running on gitlab - this potentially explains the query variation we're seeing elsewhere and might mean we can use exact assertions for database queries once this lands. Need to get to a green MR though..
Comment #5
catchShould be ready for review now.
Comment #6
kristiaanvandeneyndeLooks good to me. Tests also went green on my local and the changes will help me in reducing the expected results of #3421164: Log every individual query in performance tests
Comment #7
kristiaanvandeneyndeStill RTBC for all I care as you can fix on commit, but minor copy-paste mistake in a comment.
Comment #8
wim leersA few questions + nits 😇 But … I'm definitely intrigued! 🤩
Comment #9
kristiaanvandeneyndeI applied the nits, the only two things still left for discussion are:
Comment #10
kristiaanvandeneyndeDuring one of many tests locally, StandardPerformanceTest::testAnonymous() failed on the checksum count:
150 is greater or equal to 143 and is smaller or equal to 146This happened on only one out of 10ish test runs
Comment #11
wim leers+1 for follow-up to maintain consistency. Tagged for that.
Posted suggestion (https://git.drupalcode.org/project/drupal/-/merge_requests/6643/diffs#no...), proof that it works: https://3v4l.org/VsQ3n
Comment #12
kristiaanvandeneyndeEdit: Leaving below comment up, but prefacing with the fact that, after reading the docs on php.net, it seems common practice to seemingly misuse the match() statement for the sake of brevity. So I withdraw my insistence on using switch() even though semantically it seems like the right choice.
Having said that, I am a bit appalled at how lenient the match() statement is in terms of what you can do inside of it. Things like
match(true)followed by a bunch of unrelated conditions and actual function calls returning any random value that is not even used afterwards feels really, really dirty. We're sacrificing readability and purpose for the sake of being able to write something in a few lines fewer.While a match() definitely looks nicer and is more concise, I'm worried about the fact that we're not using it the way it was intended. We're executing an increment in a place where you're supposed to return a value and I'm not sure if php will keep allowing that for all eternity.
Would you agree with a switch() instead?
The exception also takes care of your concern that we'd forget to count a newly monitored operation. I mean, it's definitely more verbose than the match() statement, but semantically it seems more correct?
Comment #13
catchI opened the follow-up for hrtime in #3422642: Use hrtime() instead of microtime() for timing things so removing the tag.
It seems like the worst they could enforce is explicitly returning NULL?
I personally find the match statement more readable than the switch statement (no break or default to worry about, which can always theoretically go wrong if one gets misplaced).
Comment #14
kristiaanvandeneyndeYeah, let's go with match(). I do agree it's far more readable.
I withdrew my objection in the edit above. I just feel like this is a regression to oldschool php where things have magic meanings. How would you teach the difference now between switch() and match() if the latter can be duckpunched into behaving like the former :)
Comment #15
wim leers#12: let
match()grow on you 😊 It had to grow on me too. The #1 benefit ofmatch()is not brevity, but the language-level help to ensure all cases are covered — seeUnhandledMatchError.#14: read https://stitcher.io/blog/php-8-match-or-switch — I'd argue the opposite is true: it's
switch()that contains more magic thanmatch()😅Keeping at for implementing
match()since both @catch and @kristiaanvandeneynde are on board now 😊Comment #16
kristiaanvandeneyndeSwitched to enum/match and also made sure that we use the name property to get a string we can send to OpenTelemetry as I've read enums do not support __toString().
Furthermore made sure we actually send the cache tag stuff to OT (in our case Grafana) too and found something interesting. We are getting a bunch of calls where no tags were provided. See attached screenshot below. Only the one at the bottom actually had any tags, many of the resulting spans had none.
Comment #17
kristiaanvandeneyndeCome to think of it, these empty checks would explain the high number of cache tag operations we're seeing. Implementing code knows it's safe to call these operations with empty arrays and therefore does not bother checking how many tags there are before sending the (empty) list to the respective methods.
If we were to run an empty check before we call any operation, the number would go down drastically.
Comment #18
kristiaanvandeneyndeRegarding
declare(strict_types=1);vsdeclare(strict_types = 1);I found >100 and ~90 use cases of them respectively. So unless we want to standardize on those I'd just leave it as is. PhpStorm seemed to manually add the spaces on my end.Comment #19
wim leers🚀 This will be very helpful to improve Drupal's use of cache tags 😊 Thanks for making this happen!
Comment #20
wim leersOh and I think we already need a follow-up for the first finding, by @kristiaanvandeneynde in #16: we can optimize
\Drupal\Core\Cache\CacheTagsChecksumTrait::isValid()with a trivial early return:Comment #21
catchOpened #3422981: Return early in CacheTagsChecksumTrait::isValid() (and possibly elsewhere) if there are no tags to check.
Comment #22
alexpottCommitted and pushed d66403c93d to 11.x and d552da855a to 10.3.x. Thanks!