-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
[REF] AllCoreTables - Simplify array lookups & transformations #29368
Conversation
Previously it was caching the same data in 3 arrays. This consolidates it to a single array, because calling array_column() it's that hard.
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
This cuts some code out, removes a couple of array-indexes but I don't think the memory/efficiency change will be noticeable. I mean it's ~40times slower now but we probably won't notice. So if this is a step towards something good, then let's merge. |
Indeed, if we had to run one of the functions in this class 100,000 times per page request we would have some performance problems (but probably for other reasons, like, why are we calling the same function 100,000 times??? 😆). But I'm not quite sure which function you're benchmarking here, I don't think I've directly changed any |
@colemanw sure, array_column is even slower (100x or more) - because every access you're re-indexing the entire array, just to then access a single value. vs a small memory saving (dunno how to calculate that, but suspect ~20kB).
I had looked at this code? https://github.com/civicrm/civicrm-core/pull/29368/files#diff-d5169860458a5b642ed284a44d5e0bf1de17d8c319a824185c60fdf29ffb60ebR375-R380 |
LOL! Good to know! |
@artfulrobot based on your benchmarking I'm tempted to rework this even more so that we sacrifice a little memory (but probably not more than before this PR) and cache an array with 3 indexes:
Before this PR maybe 75% functions in this class used an index, after this PR maybe 50%? The above structure would allow 100% of them to use an index. |
Ok @artfulrobot you inspired me. #29377 saves a bit of memory and speeds things up. Best of both! |
FWIW, I got the results back from comparing 3 branches with multiple runs of the The branch
These are runtimes measured in seconds. (Range of 2060-2979 s aka 34-49 min.) Results were generally pretty consistent for a suite+branch (with one major outlier on (Obviously, test-benchmarks are only one kind of benchmark. It's just the convenient one...) (Aside: I'm not sure why |
Wow @colemanw good work ! |
Overview
Simplifies code, saves memory, deprecates an unused function.
Preliminary cleanup for dev/core#4999.
Before
Caches the same data 3 times in 3 different arrays.
After
Consolidates it to a single array, because calling
array_column()
really isn't hard.Comments
This will make further changes easier if we decide to cache this data in a different way, now there's only one thing to store & retrieve.
Also deprecates an unused function.