This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 149538

Summary: low performance of Annotations.addAnnotation()
Product: editor Reporter: Alexander Simon <alexvsimon>
Component: Hints & AnnotationsAssignee: Jan Lahoda <jlahoda>
Status: RESOLVED FIXED    
Severity: blocker CC: dstrupl, misterm
Priority: P2 Keywords: PERFORMANCE
Version: 6.x   
Hardware: Sun   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on:    
Bug Blocks: 149086    
Attachments: Patch for testing.

Description Alexander Simon 2008-10-08 16:51:23 UTC
Class Annotations has a sorted by line number annotation storage.
But when annotation is added the sequential search is used.
It a wast of time.
For example: adding of 1500 annotations consume about 2 seconds.
See code fragment:
------------------------------------------------
                // insert newly created LineAnnotations into sorted array
                boolean inserted = false;
                for (int i=0; i < lineAnnotationsArray.size(); i++) {
                    if (((LineAnnotations)lineAnnotationsArray.get(i)).getLine() > lineAnnos.getLine()) {
                        lineAnnotationsArray.add(i, lineAnnos);
                        inserted = true;
                        break;
                    }
                }
                if (!inserted)
                        lineAnnotationsArray.add(lineAnnos);
------------------------------------------------
Comment 1 Vitezslav Stejskal 2008-10-09 13:02:32 UTC
Yeahm, it sounds rather inefficient.
Comment 2 Max Sauer 2008-10-27 12:06:57 UTC
I'll look at it for 7.0
Comment 3 David Strupl 2010-05-11 07:32:17 UTC
*** Bug 183610 has been marked as a duplicate of this bug. ***
Comment 4 Jan Lahoda 2010-05-11 08:07:02 UTC
Created attachment 98745 [details]
Patch for testing.
Comment 5 Jan Lahoda 2010-05-11 08:10:45 UTC
Alexander, could you please try the above patch? The change is that binary search is used when adding annotation. I hope that could bring big enough performance improvement for 6.9. In the future we could think about extending the API, possibly to do something similar as the AnnotationHolder does, which should further improve the performance.

Thanks.
Comment 6 Alexander Simon 2010-05-11 08:24:42 UTC
(In reply to comment #5)
> Alexander, could you please try the above patch?
Ok, will try today.
Comment 7 Alexander Simon 2010-05-11 13:24:47 UTC
Annotations does not have hot spots now.
Comment 8 Jan Lahoda 2010-05-11 14:58:09 UTC
Thanks, I have applied the patch:
http://hg.netbeans.org/jet-main/rev/36a16ca5f798

I have also filled an enhancement (bug #185928) to cover possible future addition of a method that would allow to set many annotations at once.
Comment 9 Quality Engineering 2010-05-14 04:07:30 UTC
Integrated into 'main-golden', will be available in build *201005132200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/
User: 
Log: