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

Big Performance Improvement #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

timbarsotti
Copy link

Noticed this consumes a lot of CPU time with lots of triggers. Made a significant improvement to TriggerHandler to improve this. Write found here: http://timbarsotti.com/2020/04/21/triggerhandler-performance/

@renatoliveira
Copy link
Contributor

This is great, I didn't know that we had this kind of performance hit by getting the class' name that way.

The way you propose doing this, however, exposes a risk: if the name contains a typo then the bypass API will fail if used with the correct handler name. I'm sure this is a small price to pay, though.

@codefriar
Copy link
Collaborator

codefriar commented Apr 21, 2020 via email

@vr8hub
Copy link

vr8hub commented Jun 1, 2020

Have you found out anything more, @codefriar? Can this be merged, or do you have another solution? Thanks!

@kevinohara80
Copy link
Owner

kevinohara80 commented Jun 13, 2020

I don't really like losing the automated handler name resolution and forcing the name through a parent constructor. A really simple solution would just be to cache the handlername in a static variable after the first call like what @codefriar said.

It's not expensive to do it once, but it's being called repeatedly in the current solution which is what is causing the CPU cycles.

@vr8hub
Copy link

vr8hub commented Jun 13, 2020

I have another PR I'm holding until PR30 is approved; if @timbarsotti doesn't get to it first, I'll add this as well.

@timbarsotti
Copy link
Author

@kevinohara80 the issue I see with a static variable is when multiple handlers are in play in a single execution context.
For example, if a ContactTrigger fires an AccountTrigger, the static would be the same per execution cycle.

By adding this change, it doesn't remove the dynamic reading of the TriggerHandler, but allows the dynamic to be overridden with a super constructor. TriggerHandler works fine without calling super().

@renatoliveira yes - risk is there.

@kevinohara80
Copy link
Owner

kevinohara80 commented Jul 8, 2020

@timbarsotti I'm not following this...

the issue I see with a static variable is when multiple handlers are in play in a single execution context.
For example, if a ContactTrigger fires an AccountTrigger, the static would be the same per execution cycle.

So you're saying you'd want to be able to compute some sort of dynamic trigger handler name at runtime?

P.S. I see that the handlerName is being memoized which is great. I also don't see an issue with overloading the constructor with a supplied handlerName. Maybe what threw me off initially was the change to the docs mentioning performance improvements by using the overloaded constructor. The BIG performance improvement is the memoizing of the handler name. Supplying a handlerName in the constructor is not going to be a noticeable difference in performance as the alternative is only going to compute a handlerName once.

@imagina
Copy link

imagina commented Apr 15, 2021

Any reason this PR is not yet accepted?

if(String.isBlank(this.handlerName)) {
this.handlerName = String.valueOf(this).substring(0,String.valueOf(this).indexOf(':'));
}
return handlerName;

Choose a reason for hiding this comment

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

Suggested change
return handlerName;
return this.handlerName;

wmccullough-opengate pushed a commit to OpenGateConsulting/sfdc-trigger-framework that referenced this pull request Nov 27, 2021
…er handler name and method to set the name (see kevinohara80#29) to improve performance. Added new constructor to accept trigger handler name. Added test method for new constructor. Updated README.md to show examples of using new constructor.
@sfdeveloperhub
Copy link

@kevinohara80 , just reviving the discussion :), and explore if this one or what @vr8hub had around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants