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 — [core] CPD: Optimize --skip-lexical-errors option by woongsikchoi · Pull Request #3385 · pmd/pmd

Conversation

@woongsikchoi

@woongsikchoi woongsikchoi commented Jul 6, 2021

Copy link
Copy Markdown
Contributor

Describe the PR

This PR optimizes the state saving mechanism for --skip-lexical-errors option:

  1. Instead of copying the tokens array for all files processed so far, just save the array index and remove entries after the index when doing the recovery. This is appropriate because tokenizing the current file can't affect the tokens of previous files even when a lexical error occurs.
  2. Similarly, instead of copying the "token content to unique integer" map, save the current map size and remove entries added afterwards when doing the recovery. The added entries can be easily identified because the unique integer is assigned as "current map size + 1".

I did some benchmarking and it shows that the performance gain is substantial for large projects:

  • Project: https://github.com/pmd/pmd/ (Java / 2,871 files / 225,752 lines)
    • Before: 5.3 sec
    • After: 1.8 sec
  • Project: https://github.com/Automattic/wp-calypso (JavaScript / 5,348 files / 584,286 lines)
    • Before: 22.6 sec
    • After: 2.8 sec
  • Project: https://github.com/SAP/openui5 (JavaScript / 11,746 files / 2,819,699 lines)
    • Before: 450.7 sec
    • After: 28.1 sec

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.

wcho and dev-sungmin-kim reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@woongsikchoi
[core] CPD: Optimize --skip-lexical-errors option
c4bbd6b
@jsotuyod

jsotuyod commented Jul 6, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This looks great. I'd probably review the semantics, but certainly a valid approach and as shown, the reduced allocations should greatly improve the performance.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod jsotuyod added this to the 6.37.0 milestone Jul 6, 2021
@jsotuyod jsotuyod added for:performance The goal of this change is to improve PMD's performance in:cpd Affects the copy-paste detector labels Jul 6, 2021
@jsotuyod jsotuyod self-assigned this Jul 6, 2021
@jsotuyod jsotuyod linked an issue Jul 6, 2021 that may be closed by this pull request
[core] CPD should avoid unnecessary copies when running with --skip-lexical-errors #3387
Closed
jsotuyod added a commit that referenced this pull request Jul 6, 2021
@jsotuyod
Update changelog, refs #3385
bd4caa6
@jsotuyod
jsotuyod merged commit c4bbd6b into pmd:master Jul 6, 2021
@jsotuyod

jsotuyod commented Jul 6, 2021

Copy link
Copy Markdown
Member

Thanks for the contribution, this will be part of the following release.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ghost

ghost commented Jul 6, 2021

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

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

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

adangel
adangel reviewed Jul 8, 2021
View reviewed changes
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java
private int tokensMapSize;

public State(List<TokenEntry> entries) {
public State() {

@adangel adangel Jul 8, 2021

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.

@jsotuyod I wonder, how strict we should see compatibility here. Technically this changes TokenEntry.State, which is not internal, but public API and could potentially be used by someone...

Should we simply re-add these old constructor and method as deprecated?

I had a short look at CPD, and the TokenEntry class is part of the public API when retrieving the results of CPD (via Match -> Mark -> TokenEntry). So we can't simply internalize the whole TokenEntry class...

Sorry, something went wrong.

Uh oh!

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

All reactions

@jsotuyod jsotuyod Jul 8, 2021

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.

good point. Yeah, that should work

Sorry, something went wrong.

Uh oh!

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

All reactions

@oowekyala oowekyala Jul 8, 2021

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.

Probably, TokenEntry.State should be internal and deprecated

Sorry, something went wrong.

Uh oh!

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

All reactions
@adangel adangel mentioned this pull request Jul 15, 2021
[core] Internalize cpd.TokenEntry.State #3409
Merged
1 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jsotuyod jsotuyod jsotuyod left review comments
@adangel adangel adangel left review comments
@oowekyala oowekyala oowekyala left review comments

Uh oh!

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

Assignees

@jsotuyod jsotuyod

Labels

for:performance The goal of this change is to improve PMD's performance in:cpd Affects the copy-paste detector

Projects

None yet

Milestone

6.37.0

Development

Successfully merging this pull request may close these issues.

[core] CPD should avoid unnecessary copies when running with --skip-lexical-errors

Uh oh!

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

4 participants

@woongsikchoi @jsotuyod @adangel @oowekyala
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.