Skip to content
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

Code cleanup on greeting processing #24129

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Aug 2, 2022

Overview

Code cleanup on greeting procssing

Before

Each of the three greetings parsed separately, with separate calls to the greeting processor

After

one combined call

Technical Details

Ideally sort_name & display_name would be added in - but let's see what happens...

Comments

I thought this would speed up performance but in testing so far it doesn't - however, the processing of greetings has a significant speed impact so I'm investigating why - which doesn't negate this PR as a code cleanup / move away from legacy functions

@civibot
Copy link

civibot bot commented Aug 2, 2022

(Standard links)

@civibot civibot bot added the master label Aug 2, 2022
@eileenmcnaughton eileenmcnaughton changed the title Improve performance of greeting procssing Improve performance of greeting processing Aug 3, 2022
@eileenmcnaughton eileenmcnaughton changed the title Improve performance of greeting processing Code cleanup on greeting processing Aug 3, 2022
@seamuslee001
Copy link
Contributor

@johntwyman @andrew-cormick-dockery @anthonyblond you folks might be interested in this

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 the test fails are hard to know what to do with - I removed an extraneous db lookup that is no longer required for the internal workings of the BAO:create - but some tests check the output from them. I suspect this is just lazy tests - ie not doing a get but haven't completely decided

@eileenmcnaughton
Copy link
Contributor Author

Test Result (5 failures / +5)api\v4\Action\UpdateContactTest.testUpdateWithIdInWhereapi\v4\Action\UpdateContactTest.testUpdateWithIdInValuesapi_v3_ContactTest.testCreateApiKey with data set "APIv3"api_v3_ContactTest.testCreateApiKey with data set "APIv4"CRM_Core_BAO_ActionScheduleTest.testContactModifiedAnniversary

Test Result (5 failures / +5)
api\v4\Action\UpdateContactTest.testUpdateWithIdInWhere
api\v4\Action\UpdateContactTest.testUpdateWithIdInValues
api_v3_ContactTest.testCreateApiKey with data set "APIv3"
api_v3_ContactTest.testCreateApiKey with data set "APIv4"
CRM_Core_BAO_ActionScheduleTest.testContactModifiedAnniversary

@eileenmcnaughton
Copy link
Contributor Author

Note that pre-existing test cover is solid here.

My performance testing has some queries eliminated here (perhtaps fifteen - this query output shows the queries before patch three, which eliminated the beige one)

However, the performance problem is not notably improved & I'm going to do some php profiling since we are seeing a contact create take about three times as long (150 ms vs 45ms) and the queries only seem to add up to a couple of ms. My guess is that there might be something in there that is php-processing instensive and does not have caching. That is non-blocking on this. I am happy this is an improvement

@eileenmcnaughton
Copy link
Contributor Author

This latest is giving me a significant improvement. My import test set add 500 contributions & updates 500 contacts. My best speed is 667 per minute - with skip_greeting_processing it is 234 per minute. With this patch I get to 526 per minute

The speed difference appears to be in the php layer, not the extra queries - with apiv4 metadata functions being a possible culprit - there is something weird in that 5 api calls on the same contact seems not much different to 1, - but one being markedly different to none. That would not be so odd except that it is on a per contact basis - perhaps some cache-clear per contact is an issue, but note that I have opportunistic cache flushing off...

@eileenmcnaughton
Copy link
Contributor Author

ohh fun - I just got it back to 667 per minute... with a cache fix... pushing up now

@eileenmcnaughton
Copy link
Contributor Author

oh wow - the cache fix with NO OTHER CHANGES gets me from 234 per minute to 577 per minute....

@eileenmcnaughton
Copy link
Contributor Author

Fixed another cache miss - 612 per minute

Note that I'm using Redis caching - for sites using Array caching there is likely to be no change in these caching fixes as the difference is use of the array cache facade

@eileenmcnaughton eileenmcnaughton changed the title Code cleanup on greeting processing [WIP] - Code cleanup on greeting processing Aug 4, 2022
@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton eileenmcnaughton force-pushed the greeting_perf branch 5 times, most recently from f0ae5fa to 171c6fb Compare August 18, 2022 01:37
@eileenmcnaughton eileenmcnaughton changed the title [WIP] - Code cleanup on greeting processing Code cleanup on greeting processing Aug 18, 2022
@eileenmcnaughton
Copy link
Contributor Author

I've moved all the other commits out of this PR & this PR is now primarily a refactor / code cleanup of legacy functions.

It WILL remove some db queries but these proved to be the least compelling of the performance improvements I trialled.

Note test cover is super solid on this - including in the tests 'touched' in this PR (I only removed incorrect throws tags)

$row = $tokenProcessor->getRow(0);
foreach ($greetings as $greetingKey => $greetingString) {
$parsedGreeting = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($row->render($greetingKey)));
$updateQueryString[] = " $greetingKey = '$parsedGreeting'";
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton the one thing I wonder bout here is should we do a test for checking if $parsedGreeting != current passed greeting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm yeah - could do - I think it is no change at the moment - ie the check is not there already - so I'd probably look at it as a follow up

@seamuslee001
Copy link
Contributor

ok test coverage should be fine here

@seamuslee001 seamuslee001 merged commit c2b6898 into civicrm:master Aug 18, 2022
@seamuslee001 seamuslee001 deleted the greeting_perf branch August 18, 2022 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants