GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] New AvoidDebugStatements rule to mitigate performance impact by jonathanwiesel · Pull Request #3319 · pmd/pmd

Conversation

@jonathanwiesel

@jonathanwiesel jonathanwiesel commented May 29, 2021

Copy link
Copy Markdown
Contributor

Describe the PR

Flags usage of System.debug statements since it's demonstrated that impacts performance even when no debug traces are active. Also promoting the usage of Apex Replay Debugger and Checkpoints that doesn't pollute the code and grants most of the functionality.

Related issues

  • Fixes [apex] Avoid debug statements since it impact performance #3307

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jonathanwiesel
Add apex AvoidDebugStatements rule
cb60488
@ghost

ghost commented May 29, 2021 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
1 Message
📖 This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
✅ No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

rsoesemann commented Jun 8, 2021

Copy link
Copy Markdown
Member

Looks like you have created this rule and the fix based on my tweet and gist https://gist.github.com/rsoesemann/8a612d9b28d9c572dfb203c9769a5809

Why did you remove the ignoring of explicit LoggingLevels? I think they often show that the developer knows what he does.
I also have seen developers to leave LoggingLevel.ERROR debugs in their production code. It will never harm performance.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jonathanwiesel

jonathanwiesel commented Jun 8, 2021

Copy link
Copy Markdown
Contributor Author

Hi @rsoesemann, I didn't see your tweet or gist before, sorry if this looked like me trying to "rob" your implementation and applying it here, it was never my intention to claim authorship.

Regarding what you mentioned about LoggingLevels, looking at the blog post mentioned in the issue it seems that even when no debug logs are being captured debug statement still do execute (but not written to a log), therefore the parsing and transformation of complex datatypes referenced in the debug statement could impact performance.

Although it is true that the blog post only makes reference to simple System.debug() statements (no specific LoggingLevel), however the docs mention the following regarding the default LoggingLevel in such case:

debug(msg)
Writes the specified message, in string format, to the execution debug log. The DEBUG log level is used.

So implicitly there's a LoggingLevel set (the DEBUG one) that, even when no debug logs are being captured the performance gets affected.

If you think this may not be deterministic, we could try replicating the same scenario mentioned in the blog post with explicit LoggingLevel values to determine if something changes.

rsoesemann reacted with thumbs up emoji rsoesemann reacted with eyes emoji
All reactions
  • 👍 1 reaction
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

rsoesemann commented Jun 9, 2021

Copy link
Copy Markdown
Member

Hi @jonathanwiesel I was happy to see you add this rule and have no issue with ownership. To be honest, for years I was the only guy creating rules and I am happy to see contributions. Follow me on Twitter @rsoesemann and you will understand.

I see you point and trust Keirs measurements but I fear that many people will deactivate that rule because it will false-negative their important System.debug(LoggingLevel.ERROR, 'important but seldom state'); .

  1. Do you agree that THIS is a valid case and should be ignored?
  2. What about changing the rule to ignore ERROR level OR add a parameter?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jonathanwiesel

jonathanwiesel commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

@rsoesemann I'm quite happy to contribute to the project, I've contributed a couple of times in the last few months and feels great, and I totally understand the feeling of being the only one caring for Apex 😉 (unfortunately my knowledge in PMD related development is scarce).

I have no reasons not to trust Keirs research, is very valuable input from a reputable member of the community 🥇

I'm aware that people may want to deactivate the rule entirely because of false-negatives, but for such valid use cases that the debug statements are in fact necessary developers can use the suppression mechanism for those (SuppressWarning annotation or NOPMD comment, as mentioned in the issue), that way no matter the LoggingLevel a debug statement can still be valid if consciously suppressing it.

If we only had debug statements as a tool for debugging I would be inclined to be more permissive but since we have the Replay Debugger and Checkpoints (with their respective limitations of course) I feel like most of the use cases for debug statements could be managed using those other means instead of abusing on debug statements which has been demonstrated to impact performance even when not captured.

What do you think?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Jun 10, 2021
adangel
adangel reviewed Jun 10, 2021
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

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.

Thanks for the PR!
I'm no expert for Apex and I don't know all the options/alternative/state-of-the-art, so I leave the decision to you guys.
The rule as it is now, is very simple, so basically only little maintenance for the pmd project.
The issue itself #3307 received a couple of 👍, so it seems to scratch a real itch.

I see a couple of ways to go forward:

  • Integrate this rule as it is now and see, what feedback we receive ("just try it")
  • Add a parameter to allow error logs by default (I would assume, that even in Apex you always want to see the errors of your application...)

The other point

people may want to deactivate the rule entirely

They can only deactivate the rule, if they activated it before...

The question is more: should we add this new rule to the quickstart ruleset activated or just as a comment?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

jonathanwiesel and others added 3 commits June 10, 2021 16:08
@jonathanwiesel @adangel
Fix typo
3bdac31
Co-authored-by: Andreas Dangel <[email protected]>
@jonathanwiesel
Add more clarification on rule usage
5dc62f1
@jonathanwiesel
More clarification
e1529f0
@jonathanwiesel

jonathanwiesel commented Jun 10, 2021

Copy link
Copy Markdown
Contributor Author

@adangel IMHO I would ship it like it is, although I have not been around as much as @rsoesemann and you 😉 so you probably know better than me what could be better for the community.

rsoesemann reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

rsoesemann commented Jun 17, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I am absolutely fine with your arguments @jonathanwiesel and shipping the rule as is. Even if I agree with @adangel proposal. Allowing LoggingLevel.ERROR would be better for me. But as it is an XPath rule it can be easily adjusted by anyone.

jonathanwiesel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel self-assigned this Jun 18, 2021
@adangel adangel added this to the 6.36.0 milestone Jun 18, 2021
adangel
adangel approved these changes Jun 18, 2021
View reviewed changes
adangel added a commit that referenced this pull request Jun 18, 2021
@adangel
[doc] Update release notes (#3307, #3319)
ea74775
adangel added a commit that referenced this pull request Jun 18, 2021
@adangel
Merge pull request #3319 from jonathanwiesel:avoiddebugstatements
e79facb
[apex] New AvoidDebugStatements rule to mitigate performance impact
#3319
@adangel
adangel merged commit e1529f0 into pmd:master Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

6.36.0

Development

Successfully merging this pull request may close these issues.

[apex] Avoid debug statements since it impact performance

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jonathanwiesel @rsoesemann @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.