Bug 44362 - [painting] Should not search for occurrences if element under cursor is the same
Summary: [painting] Should not search for occurrences if element under cursor is the same
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2003-10-07 17:25 EDT by Simeon Zverinski CLA
Modified: 2005-04-22 11:18 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simeon Zverinski CLA 2003-10-07 17:25:45 EDT
I would like to drop here a new feature request. I think it would be very 
useful to highlight all variable occurrences when the editor’s cursor is 
located over the variable. It’s also useful to be able to navigate between 
these occurrences to understand the variable usage evolution. I have already 
written plugins for JBuilder and JDeveloper that do this. If you want to see 
how it works, you can get them from http://home.t-
online.de/home/simeon.zverinski/variablehighlighter/.
Comment 1 Dani Megert CLA 2003-10-08 05:26:50 EDT
Sounds like a good feature.
Comment 2 Simeon Zverinski CLA 2004-04-29 19:10:24 EDT
First of all, I'd like to thank you for accepting and implementing this 
feature. I was looking on your progress in this regard and it looks very 
promising. And I really like the idea of extending occurrence highlighting to 
all "java items". BTW, I've got some mails where people say they miss this 
feature in Eclipse.

I suggest, there are two things that can improve the usability of it:

1. Occurrence navigation. In my plugin for JBuilder it's possible to move the 
cursor to the previous, next, first and original occurrences by pressing ALT-
Arrow keystrokes. It is very useful for relatively big classes to check, for 
example, all variable assignments.

2. The highlighting delay should be applied only when a document is changed. 
When the cursor is moved, it shouldn't be any delays to highlight a new 
occurrences under it.

Thanks again for your work,
Simeon
Comment 3 Dani Megert CLA 2004-04-30 06:12:41 EDT
re 1: good idea
re 2: the occurrence marker is a post selection listener hence the delay. This
is intentional (performance).

Did you see the new Occurrence preference page (I20040428)?
Comment 4 Simeon Zverinski CLA 2004-05-02 18:46:18 EDT
I've looked at the new preference page and, as you could expect, I like it :) 
And if you go in this direction, then the next step would be to implement 
different configurable highlight colors for different occurrence types. For 
example, it could help to distinguish local variables from class fields.

Regarding the delay, I don't really understand the performance problem. The 
only heavy operation is the code parsing, which really requires a delay during 
typing. But when the caret is moved, the document is not changed. In my plugin 
I use some optimized information collected during parsing to highlight 
variable occurrences and it works quite instant for caret movement. I'm not 
familiar with your implementation, but even if you traverse the AST, it should 
be fast enough for the majority of the modern computers. I really don't think 
this issue is so important to spend significant efforts for making it better 
(I just get use to something different). But could you make the delay 
configurable?
Comment 5 Dani Megert CLA 2004-05-03 04:48:33 EDT
>For example, it could help to distinguish local variables from class fields.
Checkout yet another pref page: Java > Editor > Semantic Highlighting

It is a time/space question: keeping an AST is discouraged due to it's size
hence we have to compute it whenever the selected Java element changes.
Comment 6 Simeon Zverinski CLA 2004-05-03 17:22:48 EDT
Java > Editor > Semantic Highlighting - great!

What is the size of AST that it's a problem to keep it for several opened 
editors? I thought it's kept anyway as a model for the Outline view. Could you 
keep it only for one active editor? Did you consider to use a weak reference?

And I think there is another drawback with your approach. If you compute AST 
for every caret event, you create a lot of objects in memory that causes GC to 
be run more often than necessary. And GC delays are really annoying.
Comment 7 Dani Megert CLA 2004-05-04 11:48:11 EDT
>What is the size of AST that it's a problem to keep it for several opened 
>editors?
Ask on the J Core mailing list.

> I thought it's kept anyway as a model for the Outline view.
No: AST and Java Model elements is not the same. What makes you think so?

>Could you keep it only for one active editor? Did you consider to use a weak
>reference?
We already do this i.e. we keep at most one in the cache. What makes you think
we don't do this? Note: if you work in one editor then we "only" do the
occurrence searching not the AST creation.

>And I think there is another drawback with your approach. If you compute AST 
>for every caret event,
Correct: we should either cache the last Java element or ast node key for the
caret position and only search occurrences if this changed.

Can I adapt the summary to reflect this?
Comment 8 Simeon Zverinski CLA 2004-05-04 17:50:55 EDT
> > I thought it's kept anyway as a model for the Outline view.
> No: AST and Java Model elements is not the same. What makes you think so?

I'm not familiar with your implementation. I thought it just could be.

> >Could you keep it only for one active editor? Did you consider to use a weak
> >reference?
> We already do this i.e. we keep at most one in the cache. What makes you 
think
> we don't do this? Note: if you work in one editor then we "only" do the
> occurrence searching not the AST creation.

This makes me really confused. Didn't you say in the comment # 5:
"It is a time/space question: keeping an AST is discouraged due to it's size
hence we have to compute it whenever the selected Java element changes." ?

> >And I think there is another drawback with your approach. If you compute 
AST 
> >for every caret event,
> Correct: we should either cache the last Java element or ast node key for the
> caret position and only search occurrences if this changed.

It's even more confused for me. I was talking about AST creation, because it 
was my understanding from the comment # 5. It seems you really ment something 
different.

> Can I adapt the summary to reflect this?

OK. My point from the beginning was: if you don't create a new AST with each 
caret event (now I know - you don't!), the occurrence search operation should 
be fast enough to avoid any highlight delay usage when a caret is moved. If 
you could manage it, I'm sure you will like it too.
Comment 9 Dani Megert CLA 2004-05-05 02:56:24 EDT
time permitting for 3.0
Comment 10 Kai-Uwe Maetzel CLA 2004-06-03 08:56:47 EDT
no action for 3.0
Comment 11 Tod Creasey CLA 2005-03-07 11:57:26 EST
Adding my name to the cc list as we are now tracking performance issues more
closely. Please remove the performance keyword if this is not a performance bug.
Comment 12 Mike Wilson CLA 2005-04-21 13:45:45 EDT
Is something going to be done about this for R3.1?
Comment 13 Dani Megert CLA 2005-04-22 11:18:49 EDT
Thanks to the document modification stamp that I just introduced this week I
could nicely improve this. We now only recompute if the caret is outside the
word that caused the previous computation.