netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

org.netbeans.modules.java.hints.bugs.Unused doesn't cancel properly

Open mbien opened this issue 3 years ago • 1 comments

based on delivery for the slim chance that this gets a review

  • streams are not very good at canceling
  • by using a plain loop we can simply break out of it
  • further: findUnused is actually very fast, convertUnused is the slow part and wasn't cancelable before, the original code might have worked if findUnused returned a stream instead of a list and everything would be one pipeline (this would make the fix more complicated)

issue:

  • a synthetic file with 10k fields pins a thread for about 20s at 100%
  • most editor features don't work during that time, e.g completion
  • hint is enabled by default

discussion:

noticed this while benchmarking other issues (#4500)

#3886 mentioned the poor performance of org.netbeans.modules.java.hints.bugs.Unused and also that it isn't cancelable. #4204 attempted to fix some of it, however I am not so sure that this worked.

test: FieldsOfJoy10k_Unused_hint.java.txt

scroll down to:

    // hints -> probable bugs -> unused element
    // org.netbeans.modules.java.hints.bugs.Unused#unused
    private void something() {
        this.     // code change triggers hint and pins cpu to 100%,
                  // this blocks completion etc. does cancel work?
    }

Unused#convertUnused / JavaFixUtilities#safelyRemoveFromParent use most of the time and they were not cancelable.

unused_element_hint_baseline

mbien avatar Aug 13 '22 01:08 mbien

@jlahoda thanks for review on such short notice!

mbien avatar Aug 13 '22 13:08 mbien